-
-
Notifications
You must be signed in to change notification settings - Fork 943
/
Copy pathdeprecated.ts
49 lines (42 loc) · 1.06 KB
/
deprecated.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* eslint-disable jsdoc/require-param */
/**
* A deprecation should never be done in a patch.
*/
type DeprecationSemVer = `${number}.${number}`;
/** @internal */
export interface DeprecatedOptions {
/**
* The name of the function, following the syntax `faker.[module].[function]()`.
*/
deprecated: string;
/**
* An alternative solution.
*/
proposed?: string;
/**
* The semver since when this is deprecated.
*/
since?: DeprecationSemVer;
/**
* The semver when this will be removed.
*/
until?: DeprecationSemVer;
}
/**
* @internal
*/
export function deprecated(options: DeprecatedOptions): void {
const { deprecated, since, until, proposed } = options;
let message = `[@faker-js/faker]: ${deprecated} is deprecated`;
if (since) {
message += ` since v${since}`;
}
if (until) {
message += ` and will be removed in v${until}`;
}
if (proposed) {
message += `. Please use ${proposed} instead`;
}
// eslint-disable-next-line no-undef -- Using console here is intentional and required
console.warn(`${message}.`);
}