@snaplet/copycat
Advanced tools
Comparing version 1.0.0-rc.1 to 1.1.0-rc.1
export { faker } from '@faker-js/faker'; | ||
import * as fictional from 'fictional'; | ||
import fictional__default, { Input, Maker, PlainNested, JSONPrimitive } from 'fictional'; | ||
import fictional__default, { Input, Maker, PlainNested, JSONPrimitive, HashKey } from 'fictional'; | ||
export { fictional }; | ||
@@ -46,3 +46,40 @@ export { Input, Maker as Transform } from 'fictional'; | ||
declare const phoneNumber: (input: string) => string; | ||
type PhoneNumberOptions = { | ||
/** | ||
* An array of prefixes to use when generating a phone number. | ||
* Can be used to generate a fictional phone number instead of a random one. | ||
* Using fictional phone numbers might make the generation slower. And might increase likelihood of collisions. | ||
* @example | ||
* ```ts | ||
* phoneNumber(seed, { | ||
* // Generate a French phone number within fictional phone number delimited range (cf: https://en.wikipedia.org/wiki/Fictitious_telephone_number) | ||
* prefixes: ['+3319900', '+3326191', '+3335301'], | ||
* // A french phone number is 11 digits long (including the prefix) so there is no need to generate a number longer than 4 digits | ||
* min: 1000, max: 9999 | ||
* }) | ||
* ``` | ||
* @example | ||
* | ||
* ```ts | ||
* phoneNumber(seed, { | ||
* // Generate a New Jersey fictional phone number | ||
* prefixes: ['+201555'], | ||
* min: 1000, max: 9999 | ||
* }) | ||
* ``` | ||
* @default undefined | ||
*/ | ||
prefixes?: Array<string>; | ||
/** | ||
* The minimum number to generate. | ||
* @default 10000000000 | ||
*/ | ||
min?: number; | ||
/** | ||
* The maximum number to generate. | ||
* @default 999999999999999 | ||
*/ | ||
max?: number; | ||
}; | ||
declare const phoneNumber: (input: Input, options?: PhoneNumberOptions) => string; | ||
@@ -81,5 +118,63 @@ declare const city: (input: Input) => string; | ||
declare const setHashKey: (key: string | fictional.HashKey) => void; | ||
declare const generateHashKey: (input: string) => fictional.HashKey; | ||
declare function setKey(key: string | HashKey): void; | ||
declare const setHashKey: typeof setKey; | ||
declare const generateHashKey: (input: string) => HashKey; | ||
type Store<T> = { | ||
has(value: T): boolean; | ||
add(value: T): void; | ||
}; | ||
type UniqueOptions = { | ||
/** | ||
* The maximum number of attempts to generate a unique value. | ||
* If the maximum number of attempts is reached, the method will call attemptReached and return the last generated value. | ||
* @default 10 | ||
*/ | ||
attempts?: number; | ||
/** | ||
* A callback called when the maximum number of attempts is reached. | ||
* can be used to log the error in the console of throw an error. | ||
* | ||
* @example | ||
* ```ts | ||
* const attemptsReached = (input: Input) => { | ||
* throw new Error(`copycat.unique: maximum number of attempts reached for input ${input}`) | ||
* } | ||
* copycat.unique(input, { attemptsReached }) | ||
* ``` | ||
*/ | ||
attemptsReached?: (input: Input) => void; | ||
}; | ||
/** | ||
* Will attempt to generate a unique value using the provided method. | ||
* It does so by deterministically changing the seed of generation between each attempt. | ||
* If the maximum number of attempts is reached, the method will call attemptsReached then return the last generated value. | ||
* @example | ||
* ```ts | ||
* const method = (seed: Input) => { | ||
* return copycat.int(seed, {max: 1000}) | ||
* } | ||
* const store = new Set<ReturnType<typeof method>>() | ||
* copycat.unique(input, method, store, { attempts: 100 }) | ||
* ``` | ||
*/ | ||
declare const unique: <T>(input: Input, method: (input: Input) => T, store: Store<T>, options?: UniqueOptions) => T; | ||
/** | ||
* Will attempt to generate a unique value using the provided method. | ||
* But it will preserve the duplicate if the input is already in the inputStore. | ||
* It does so by deterministically changing the seed of generation between each attempt. | ||
* If the maximum number of attempts is reached, the method will call attemptsReached then return the last generated value. | ||
* @example | ||
* ```ts | ||
* const method = (seed: Input) => { | ||
* return copycat.int(seed, {max: 1000}) | ||
* } | ||
* const resultStore = new Set<ReturnType<typeof method>>() | ||
* const inputStore = new Set<Input>() | ||
* copycat.unique(input, method, inputStore, resultStore, { attempts: 100 }) | ||
* ``` | ||
*/ | ||
declare const uniqueByInput: <T>(input: Input, method: (input: Input) => T, inputStore: Store<Input>, resultStore: Store<T>, options?: UniqueOptions) => T; | ||
type copycat_OneOfOptions = OneOfOptions; | ||
@@ -118,2 +213,4 @@ declare const copycat_bool: typeof bool; | ||
declare const copycat_timezone: typeof timezone; | ||
declare const copycat_unique: typeof unique; | ||
declare const copycat_uniqueByInput: typeof uniqueByInput; | ||
declare const copycat_userAgent: typeof userAgent; | ||
@@ -159,2 +256,4 @@ declare const copycat_username: typeof username; | ||
copycat_timezone as timezone, | ||
copycat_unique as unique, | ||
copycat_uniqueByInput as uniqueByInput, | ||
copycat_userAgent as userAgent, | ||
@@ -161,0 +260,0 @@ copycat_username as username, |
{ | ||
"name": "@snaplet/copycat", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.1.0-rc.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2860864
80145
0