Skip to content

Commit 623d274

Browse files
authored
refactor!: remove deprecations (#3553)
1 parent 160960b commit 623d274

File tree

20 files changed

+14
-939
lines changed

20 files changed

+14
-939
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const { faker } = require('@faker-js/faker');
6565
export function createRandomUser() {
6666
return {
6767
userId: faker.string.uuid(),
68-
username: faker.internet.username(), // before version 9.1.0, use userName()
68+
username: faker.internet.username(),
6969
email: faker.internet.email(),
7070
avatar: faker.image.avatar(),
7171
password: faker.internet.password(),

docs/api/ApiIndex.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,8 @@ const filtered = computed(() => {
6969
</h3>
7070
<ul>
7171
<li v-for="h of item.headers" :key="h.anchor">
72-
<!-- TODO @ST-DDT 2024-09-25: Remove this in v10 -->
7372
<a
74-
:href="
75-
item.link +
76-
'#' +
77-
(h.anchor === 'userName' ? 'username-1' : slugify(h.anchor))
78-
"
73+
:href="item.link + '#' + slugify(h.anchor)"
7974
:class="{ deprecated: h.deprecated }"
8075
>{{ h.text }}</a
8176
>

docs/guide/frameworks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import { faker } from '@faker-js/faker/locale/en';
7171

7272
describe('Testing the application', () => {
7373
it('should create an account with username and password', () => {
74-
let username = faker.internet.username(); // before version 9.1.0, use userName()
74+
let username = faker.internet.username();
7575
let password = faker.internet.password();
7676
let email = faker.internet.exampleEmail();
7777

@@ -111,7 +111,7 @@ test.describe('Testing the application', () => {
111111
test('should create an account with username and password', async ({
112112
page,
113113
}) => {
114-
const username = faker.internet.username(); // before version 9.1.0, use userName()
114+
const username = faker.internet.username();
115115
const password = faker.internet.password();
116116
const email = faker.internet.exampleEmail();
117117

src/faker.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { LocaleDefinition, MetadataDefinition } from './definitions';
22
import { FakerError } from './errors/faker-error';
3-
import { deprecated } from './internal/deprecated';
43
import type { LocaleProxy } from './internal/locale-proxy';
54
import { createLocaleProxy } from './internal/locale-proxy';
65
import { AirlineModule } from './modules/airline';
@@ -18,11 +17,9 @@ import { HackerModule } from './modules/hacker';
1817
import { HelpersModule } from './modules/helpers';
1918
import { ImageModule } from './modules/image';
2019
import { InternetModule } from './modules/internet';
21-
import type { LocationModule as AddressModule } from './modules/location';
2220
import { LocationModule } from './modules/location';
2321
import { LoremModule } from './modules/lorem';
2422
import { MusicModule } from './modules/music';
25-
import type { PersonModule as NameModule } from './modules/person';
2623
import { PersonModule } from './modules/person';
2724
import { PhoneModule } from './modules/phone';
2825
import { ScienceModule } from './modules/science';
@@ -87,29 +84,6 @@ export class Faker extends SimpleFaker {
8784
readonly vehicle: VehicleModule = new VehicleModule(this);
8885
readonly word: WordModule = new WordModule(this);
8986

90-
// Aliases
91-
/** @deprecated Use {@link Faker#location} instead */
92-
get address(): AddressModule {
93-
deprecated({
94-
deprecated: 'faker.address',
95-
proposed: 'faker.location',
96-
since: '8.0',
97-
until: '10.0',
98-
});
99-
return this.location;
100-
}
101-
102-
/** @deprecated Use {@link Faker#person} instead */
103-
get name(): NameModule {
104-
deprecated({
105-
deprecated: 'faker.name',
106-
proposed: 'faker.person',
107-
since: '8.0',
108-
until: '10.0',
109-
});
110-
return this.person;
111-
}
112-
11387
/**
11488
* Creates a new instance of Faker.
11589
*

src/modules/date/index.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@ export class SimpleDateModule extends SimpleModuleBase {
160160
*/
161161
to: string | Date | number;
162162
}): Date {
163-
// TODO @matthewmayer 2023-03-27: Consider removing in v10 as this check is only needed in JS
164-
if (options == null || options.from == null || options.to == null) {
165-
throw new FakerError(
166-
'Must pass an options object with `from` and `to` values.'
167-
);
168-
}
169-
170163
const { from, to } = options;
171164

172165
const fromMs = toDate(from, 'from').getTime();
@@ -234,13 +227,6 @@ export class SimpleDateModule extends SimpleModuleBase {
234227
max: number;
235228
};
236229
}): Date[] {
237-
// TODO @matthewmayer 2023-03-27: Consider removing in v10 as this check is only needed in JS
238-
if (options == null || options.from == null || options.to == null) {
239-
throw new FakerError(
240-
'Must pass an options object with `from` and `to` values.'
241-
);
242-
}
243-
244230
const { from, to, count = 3 } = options;
245231
return this.faker.helpers
246232
.multiple(() => this.between({ from, to }), { count })
@@ -486,21 +472,8 @@ export class SimpleDateModule extends SimpleModuleBase {
486472
min = 18,
487473
max = 80,
488474
refDate: rawRefDate = this.faker.defaultRefDate(),
489-
mode: originalMode,
490-
min: originalMin,
491-
max: originalMax,
492475
} = options;
493476

494-
// TODO @ST-DDT 2024-03-17: Remove check in v10
495-
const optionsSet = [originalMin, originalMax, originalMode].filter(
496-
(x) => x != null
497-
).length;
498-
if (optionsSet % 3 !== 0) {
499-
throw new FakerError(
500-
"The 'min', 'max', and 'mode' options must be set together."
501-
);
502-
}
503-
504477
const refDate = toDate(rawRefDate);
505478
const refYear = refDate.getUTCFullYear();
506479

src/modules/finance/index.ts

Lines changed: 0 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { FakerError } from '../../errors/faker-error';
2-
import { deprecated } from '../../internal/deprecated';
32
import { ModuleBase } from '../../internal/module-base';
43
import type { BitcoinAddressFamilyType, BitcoinNetworkType } from './bitcoin';
54
import {
@@ -206,171 +205,6 @@ export class FinanceModule extends ModuleBase {
206205
return `${routingNumber}${Math.ceil(sum / 10) * 10 - sum}`;
207206
}
208207

209-
/**
210-
* Generates a random masked number.
211-
*
212-
* @param length The length of the unmasked number. Defaults to `4`.
213-
*
214-
* @example
215-
* faker.finance.maskedNumber() // '(...9711)'
216-
* faker.finance.maskedNumber(3) // '(...342)'
217-
*
218-
* @since 8.0.0
219-
*
220-
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
221-
*/
222-
maskedNumber(length?: number): string;
223-
/**
224-
* Generates a random masked number.
225-
*
226-
* @param options An options object.
227-
* @param options.length The length of the unmasked number. Defaults to `4`.
228-
* @param options.parens Whether to use surrounding parenthesis. Defaults to `true`.
229-
* @param options.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`.
230-
*
231-
* @example
232-
* faker.finance.maskedNumber() // '(...9711)'
233-
* faker.finance.maskedNumber({ length: 3 }) // '(...342)'
234-
* faker.finance.maskedNumber({ length: 3, parens: false }) // '...236'
235-
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
236-
*
237-
* @since 8.0.0
238-
*
239-
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
240-
*/
241-
maskedNumber(options?: {
242-
/**
243-
* The length of the unmasked number.
244-
*
245-
* @default 4
246-
*/
247-
length?: number;
248-
/**
249-
* Whether to use surrounding parenthesis.
250-
*
251-
* @default true
252-
*/
253-
parens?: boolean;
254-
/**
255-
* Whether to prefix the numbers with an ellipsis.
256-
*
257-
* @default true
258-
*/
259-
ellipsis?: boolean;
260-
}): string;
261-
/**
262-
* Generates a random masked number.
263-
*
264-
* @param optionsOrLength An options object or the length of the unmask number.
265-
* @param optionsOrLength.length The length of the unmasked number. Defaults to `4`.
266-
* @param optionsOrLength.parens Whether to use surrounding parenthesis. Defaults to `true`.
267-
* @param optionsOrLength.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`.
268-
*
269-
* @example
270-
* faker.finance.maskedNumber() // '(...9711)'
271-
* faker.finance.maskedNumber(3) // '(...342)'
272-
* faker.finance.maskedNumber({ length: 3 }) // '(...342)'
273-
* faker.finance.maskedNumber({ length: 3, parens: false }) // '...236'
274-
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
275-
*
276-
* @since 8.0.0
277-
*
278-
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
279-
*/
280-
maskedNumber(
281-
optionsOrLength?:
282-
| number
283-
| {
284-
/**
285-
* The length of the unmasked number.
286-
*
287-
* @default 4
288-
*/
289-
length?: number;
290-
/**
291-
* Whether to use surrounding parenthesis.
292-
*
293-
* @default true
294-
*/
295-
parens?: boolean;
296-
/**
297-
* Whether to prefix the numbers with an ellipsis.
298-
*
299-
* @default true
300-
*/
301-
ellipsis?: boolean;
302-
}
303-
): string;
304-
/**
305-
* Generates a random masked number.
306-
*
307-
* @param options An options object.
308-
* @param options.length The length of the unmasked number. Defaults to `4`.
309-
* @param options.parens Whether to use surrounding parenthesis. Defaults to `true`.
310-
* @param options.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`.
311-
*
312-
* @example
313-
* faker.finance.maskedNumber() // '(...9711)'
314-
* faker.finance.maskedNumber(3) // '(...342)'
315-
* faker.finance.maskedNumber({ length: 3 }) // '(...342)'
316-
* faker.finance.maskedNumber({ length: 3, parens: false }) // '...236'
317-
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
318-
*
319-
* @since 8.0.0
320-
*
321-
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
322-
*/
323-
maskedNumber(
324-
options:
325-
| number
326-
| {
327-
/**
328-
* The length of the unmasked number.
329-
*
330-
* @default 4
331-
*/
332-
length?: number;
333-
/**
334-
* Whether to use surrounding parenthesis.
335-
*
336-
* @default true
337-
*/
338-
parens?: boolean;
339-
/**
340-
* Whether to prefix the numbers with an ellipsis.
341-
*
342-
* @default true
343-
*/
344-
ellipsis?: boolean;
345-
} = {}
346-
): string {
347-
deprecated({
348-
deprecated: 'faker.finance.maskedNumber()',
349-
proposed:
350-
"faker.finance.iban().replace(/(?<=.{4})\\w(?=.{2})/g, '*') or a similar approach",
351-
since: '9.3.0',
352-
until: '10.0.0',
353-
});
354-
355-
if (typeof options === 'number') {
356-
options = { length: options };
357-
}
358-
359-
const { ellipsis = true, length = 4, parens = true } = options;
360-
361-
let template = this.faker.string.numeric({ length });
362-
363-
if (ellipsis) {
364-
template = `...${template}`;
365-
}
366-
367-
if (parens) {
368-
template = `(${template})`;
369-
}
370-
371-
return template;
372-
}
373-
374208
/**
375209
* Generates a random amount between the given bounds (inclusive).
376210
*

src/modules/helpers/eval.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function fakeEval(
8181
do {
8282
let index: number;
8383
if (remaining.startsWith('(')) {
84-
[index, current] = evalProcessFunction(remaining, current, expression);
84+
[index, current] = evalProcessFunction(remaining, current);
8585
} else {
8686
[index, current] = evalProcessExpression(remaining, current);
8787
}
@@ -109,12 +109,10 @@ export function fakeEval(
109109
*
110110
* @param input The input string to parse.
111111
* @param entrypoints The entrypoints to attempt the call on.
112-
* @param expression The full expression to use in errors.
113112
*/
114113
function evalProcessFunction(
115114
input: string,
116-
entrypoints: ReadonlyArray<unknown>,
117-
expression: string
115+
entrypoints: ReadonlyArray<unknown>
118116
): [continueIndex: number, mapped: unknown[]] {
119117
const [index, params] = findParams(input);
120118
const nextChar = input[index + 1];
@@ -135,23 +133,7 @@ function evalProcessFunction(
135133
return [
136134
index + (nextChar === '.' ? 2 : 1), // one for the closing bracket, one for the dot
137135
entrypoints.map((entrypoint): unknown =>
138-
// TODO @ST-DDT 2023-12-11: Replace in v10
139-
// typeof entrypoint === 'function' ? entrypoint(...params) : undefined
140-
{
141-
if (typeof entrypoint === 'function') {
142-
return entrypoint(...params);
143-
}
144-
145-
// eslint-disable-next-line no-undef
146-
console.warn(
147-
`[@faker-js/faker]: Invoking expressions which are not functions is deprecated since v9.0 and will be removed in v10.0.
148-
Please remove the parentheses or replace the expression with an actual function.
149-
${expression}
150-
${' '.repeat(expression.length - input.length)}^`
151-
);
152-
153-
return entrypoint;
154-
}
136+
typeof entrypoint === 'function' ? entrypoint(...params) : undefined
155137
),
156138
];
157139
}

0 commit comments

Comments
 (0)