Comparing version
@@ -755,3 +755,2 @@ var __create = Object.create; | ||
var _uuid = __toESM(require("uuid")); | ||
var _generatePassword = __toESM(require("generate-password")); | ||
@@ -851,5 +850,19 @@ // src/data/creditCardProviders.ts | ||
// src/data/chars.ts | ||
var alphabet = `abcdefghijklnmopqrstuvwxyz`; | ||
var base10 = `123456789`; | ||
var symbols = `!"#$%&'()*+,-./:;<=>?@[]^_\`{|}~`; | ||
var passwordSymbols = `?.,!_-~$%+=`; | ||
var similarLetters = `ilLIoO0`; | ||
var chars_default = { | ||
alphabet, | ||
base10, | ||
symbols, | ||
similarLetters, | ||
passwordSymbols | ||
}; | ||
// src/helpers/replaceStrings.ts | ||
var replaceSymbols = (value) => { | ||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); | ||
const alphabet2 = chars_default.alphabet.toUpperCase().split(""); | ||
return value.split("").map((c) => { | ||
@@ -859,6 +872,6 @@ if (c === "#") | ||
if (c === "?") | ||
return arrayElement(alphabet); | ||
return arrayElement(alphabet2); | ||
if (c === "*") { | ||
if (boolean()) | ||
return arrayElement(alphabet); | ||
return arrayElement(alphabet2); | ||
else | ||
@@ -1056,3 +1069,2 @@ return number({ max: 9 }).toString(); | ||
var uuid = _uuid; | ||
var password = _generatePassword; | ||
var addLocale = (name2, localeData) => { | ||
@@ -1410,2 +1422,74 @@ const noLocales = Object.keys(locales).length === 0; | ||
}; | ||
var password = (options = {}) => { | ||
const { minLength, maxLength, numbers, symbols: symbols2, uppercases, lowercases } = options; | ||
let passUpercases = true; | ||
if (typeof uppercases === "boolean") | ||
passUpercases = uppercases; | ||
let passLowercases = true; | ||
if (typeof lowercases === "boolean") | ||
passLowercases = lowercases; | ||
if (!passUpercases && !passLowercases) | ||
throw new Error(`[uppercases] and [lowercases] can't both be false.`); | ||
const passMinLength = minLength || 6; | ||
const passMaxLength = maxLength || 10; | ||
const alphabetList = chars_default.alphabet.split(""); | ||
const numberList = chars_default.base10.split(""); | ||
let symbolList = chars_default.passwordSymbols.split(""); | ||
if (passMinLength < 5) | ||
throw new Error(`[minLength] must be > 5.`); | ||
if (passMinLength > passMaxLength) | ||
throw new Error(`[minLength] must be <= to [maxLength].`); | ||
if (passMaxLength < passMinLength) | ||
throw new Error(`[maxLength] must be >= to [minLength].`); | ||
const passLength = number({ min: passMinLength, max: passMaxLength }); | ||
let passNumbers = typeof numbers === "boolean" && !numbers ? 0 : number({ min: 1, max: Math.floor(passMinLength / 2) }); | ||
if (typeof numbers === "number") { | ||
if (numbers > passMinLength) | ||
throw new Error(`[numbers] must be <= to [minLength].`); | ||
passNumbers = numbers; | ||
} | ||
let passSymbols = typeof symbols2 === "boolean" && !symbols2 ? 0 : 1; | ||
if (typeof symbols2 === "string") { | ||
symbolList = symbols2.split(""); | ||
passSymbols = symbolList.length; | ||
} | ||
if (typeof symbols2 === "number") { | ||
passSymbols = symbols2; | ||
} | ||
if (passSymbols + passNumbers > passMinLength) | ||
throw new Error(`The sum of [symbols(${passSymbols})] and [numbers(${passNumbers})] must be <= to [minLength(${passMinLength})].`); | ||
if (passSymbols > passMinLength) | ||
throw new Error(`[symbols] must be <= to [minLength]`); | ||
let types = ["letter", "number", "symbol"]; | ||
let _passSymbols = 0, _passNumbers = 0; | ||
return array(passLength, () => { | ||
if (_passNumbers === passNumbers) { | ||
_passNumbers++; | ||
types.splice(types.indexOf("number"), 1); | ||
} | ||
if (_passSymbols === passSymbols) { | ||
_passSymbols++; | ||
types.splice(types.indexOf("symbol"), 1); | ||
} | ||
const charType = types.length === 1 ? types[0] : arrayElement(types); | ||
if (charType === "number") { | ||
_passNumbers++; | ||
return arrayElement(numberList); | ||
} | ||
if (charType === "symbol") { | ||
_passSymbols++; | ||
return arrayElement(symbolList); | ||
} | ||
const letter = arrayElement(alphabetList); | ||
if (passUpercases && passLowercases) { | ||
const toUpper = boolean(); | ||
return toUpper ? letter.toUpperCase() : letter; | ||
} else if (passUpercases && !passLowercases) { | ||
return letter.toUpperCase(); | ||
} else { | ||
return letter; | ||
} | ||
}).join(""); | ||
}; | ||
password({ numbers: 4, symbols: 2 }); | ||
var src_default = { | ||
@@ -1470,5 +1554,5 @@ setDefaultLocale, | ||
hex, | ||
password, | ||
nanoId, | ||
uuid, | ||
password, | ||
nonsecure | ||
@@ -1475,0 +1559,0 @@ }; |
@@ -688,3 +688,2 @@ var __create = Object.create; | ||
import * as _uuid from "uuid"; | ||
import * as _generatePassword from "generate-password"; | ||
@@ -784,5 +783,19 @@ // src/data/creditCardProviders.ts | ||
// src/data/chars.ts | ||
var alphabet = `abcdefghijklnmopqrstuvwxyz`; | ||
var base10 = `123456789`; | ||
var symbols = `!"#$%&'()*+,-./:;<=>?@[]^_\`{|}~`; | ||
var passwordSymbols = `?.,!_-~$%+=`; | ||
var similarLetters = `ilLIoO0`; | ||
var chars_default = { | ||
alphabet, | ||
base10, | ||
symbols, | ||
similarLetters, | ||
passwordSymbols | ||
}; | ||
// src/helpers/replaceStrings.ts | ||
var replaceSymbols = (value) => { | ||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); | ||
const alphabet2 = chars_default.alphabet.toUpperCase().split(""); | ||
return value.split("").map((c) => { | ||
@@ -792,6 +805,6 @@ if (c === "#") | ||
if (c === "?") | ||
return arrayElement(alphabet); | ||
return arrayElement(alphabet2); | ||
if (c === "*") { | ||
if (boolean()) | ||
return arrayElement(alphabet); | ||
return arrayElement(alphabet2); | ||
else | ||
@@ -989,3 +1002,2 @@ return number({ max: 9 }).toString(); | ||
var uuid = _uuid; | ||
var password = _generatePassword; | ||
var addLocale = (name2, localeData) => { | ||
@@ -1343,2 +1355,74 @@ const noLocales = Object.keys(locales).length === 0; | ||
}; | ||
var password = (options = {}) => { | ||
const { minLength, maxLength, numbers, symbols: symbols2, uppercases, lowercases } = options; | ||
let passUpercases = true; | ||
if (typeof uppercases === "boolean") | ||
passUpercases = uppercases; | ||
let passLowercases = true; | ||
if (typeof lowercases === "boolean") | ||
passLowercases = lowercases; | ||
if (!passUpercases && !passLowercases) | ||
throw new Error(`[uppercases] and [lowercases] can't both be false.`); | ||
const passMinLength = minLength || 6; | ||
const passMaxLength = maxLength || 10; | ||
const alphabetList = chars_default.alphabet.split(""); | ||
const numberList = chars_default.base10.split(""); | ||
let symbolList = chars_default.passwordSymbols.split(""); | ||
if (passMinLength < 5) | ||
throw new Error(`[minLength] must be > 5.`); | ||
if (passMinLength > passMaxLength) | ||
throw new Error(`[minLength] must be <= to [maxLength].`); | ||
if (passMaxLength < passMinLength) | ||
throw new Error(`[maxLength] must be >= to [minLength].`); | ||
const passLength = number({ min: passMinLength, max: passMaxLength }); | ||
let passNumbers = typeof numbers === "boolean" && !numbers ? 0 : number({ min: 1, max: Math.floor(passMinLength / 2) }); | ||
if (typeof numbers === "number") { | ||
if (numbers > passMinLength) | ||
throw new Error(`[numbers] must be <= to [minLength].`); | ||
passNumbers = numbers; | ||
} | ||
let passSymbols = typeof symbols2 === "boolean" && !symbols2 ? 0 : 1; | ||
if (typeof symbols2 === "string") { | ||
symbolList = symbols2.split(""); | ||
passSymbols = symbolList.length; | ||
} | ||
if (typeof symbols2 === "number") { | ||
passSymbols = symbols2; | ||
} | ||
if (passSymbols + passNumbers > passMinLength) | ||
throw new Error(`The sum of [symbols(${passSymbols})] and [numbers(${passNumbers})] must be <= to [minLength(${passMinLength})].`); | ||
if (passSymbols > passMinLength) | ||
throw new Error(`[symbols] must be <= to [minLength]`); | ||
let types = ["letter", "number", "symbol"]; | ||
let _passSymbols = 0, _passNumbers = 0; | ||
return array(passLength, () => { | ||
if (_passNumbers === passNumbers) { | ||
_passNumbers++; | ||
types.splice(types.indexOf("number"), 1); | ||
} | ||
if (_passSymbols === passSymbols) { | ||
_passSymbols++; | ||
types.splice(types.indexOf("symbol"), 1); | ||
} | ||
const charType = types.length === 1 ? types[0] : arrayElement(types); | ||
if (charType === "number") { | ||
_passNumbers++; | ||
return arrayElement(numberList); | ||
} | ||
if (charType === "symbol") { | ||
_passSymbols++; | ||
return arrayElement(symbolList); | ||
} | ||
const letter = arrayElement(alphabetList); | ||
if (passUpercases && passLowercases) { | ||
const toUpper = boolean(); | ||
return toUpper ? letter.toUpperCase() : letter; | ||
} else if (passUpercases && !passLowercases) { | ||
return letter.toUpperCase(); | ||
} else { | ||
return letter; | ||
} | ||
}).join(""); | ||
}; | ||
password({ numbers: 4, symbols: 2 }); | ||
var src_default = { | ||
@@ -1403,5 +1487,5 @@ setDefaultLocale, | ||
hex, | ||
password, | ||
nanoId, | ||
uuid, | ||
password, | ||
nonsecure | ||
@@ -1408,0 +1492,0 @@ }; |
import * as _nanoid from 'nanoid'; | ||
import * as _nanoid_nonsecure from 'nanoid/non-secure'; | ||
import * as _uuid from 'uuid'; | ||
import * as _generatePassword from 'generate-password'; | ||
declare type Locale = (string & {}) | 'en' | 'fr' | 'fr-CA' | 'es'; | ||
@@ -9,3 +8,2 @@ export declare const nanoId: typeof _nanoid; | ||
export declare const uuid: typeof _uuid; | ||
export declare const password: typeof _generatePassword; | ||
export declare const addLocale: (name: string, localeData: any) => void; | ||
@@ -20,3 +18,3 @@ export declare const setDefaultLocale: (locale: Locale) => void; | ||
export declare const arrayElement: <T>(array: T[]) => T; | ||
export declare const array: <T>(count: number, cb: (index: number) => void) => T[]; | ||
export declare const array: <T>(count: number, cb: (index: number) => T) => T[]; | ||
export declare const objectElement: (obj: any) => { | ||
@@ -149,3 +147,3 @@ key: string; | ||
useAbbr?: boolean; | ||
}) => string; | ||
}) => any; | ||
export declare const state: (options?: { | ||
@@ -190,2 +188,12 @@ locale?: Locale; | ||
export declare const filePath: () => string; | ||
interface PasswordOptions { | ||
maxLength?: number; | ||
minLength?: number; | ||
uppercases?: boolean; | ||
lowercases?: boolean; | ||
numbers?: boolean | number; | ||
symbols?: boolean | number | string; | ||
exclude?: (string & {}) | 'similar'; | ||
} | ||
export declare const password: (options?: PasswordOptions) => string; | ||
declare const _default: { | ||
@@ -235,3 +243,3 @@ setDefaultLocale: (locale: Locale) => void; | ||
}; | ||
array: <T_1>(count: number, cb: (index: number) => void) => T_1[]; | ||
array: <T_1>(count: number, cb: (index: number) => T_1) => T_1[]; | ||
lastName: (options?: { | ||
@@ -321,3 +329,3 @@ locale?: Locale; | ||
useAbbr?: boolean; | ||
}) => string; | ||
}) => any; | ||
state: (options?: { | ||
@@ -362,7 +370,7 @@ locale?: Locale; | ||
hex: (count?: number) => string; | ||
password: (options?: PasswordOptions) => string; | ||
nanoId: typeof _nanoid; | ||
uuid: typeof _uuid; | ||
password: typeof _generatePassword; | ||
nonsecure: typeof _nanoid_nonsecure; | ||
}; | ||
export default _default; |
{ | ||
"name": "minifaker", | ||
"version": "1.32.0", | ||
"version": "1.33.0", | ||
"description": "lightweight faker.js", | ||
@@ -50,3 +50,3 @@ "types": "./dist/types/index.d.ts", | ||
"crypto-browserify": "^3.12.0", | ||
"esbuild": "^0.14.10", | ||
"esbuild": "^0.14.11", | ||
"jest": "^27.4.7", | ||
@@ -60,7 +60,6 @@ "jest-extended": "^1.2.0", | ||
"@types/uuid": "^8.3.4", | ||
"generate-password": "^1.7.0", | ||
"minifaker": "file:.yalc/minifaker", | ||
"nanoid": "^3.1.30", | ||
"nanoid": "^3.1.31", | ||
"uuid": "^8.3.2" | ||
} | ||
} |
@@ -37,3 +37,3 @@ # minifaker | ||
- nanoid, uuid, generate-password | ||
- nanoid, uuid | ||
@@ -93,3 +93,3 @@ ## Example / usage | ||
```ts | ||
import { nanoId, uuid, password, nonsecure } from 'minifaker' | ||
import { nanoId, uuid, nonsecure } from 'minifaker' | ||
@@ -99,3 +99,2 @@ nanoId.nanoid() // nanoid - https://github.com/ai/nanoid | ||
uuid.v4() // uuid - https://github.com/uuidjs/uuid | ||
password.generate() // generate-password - https://github.com/brendanashworth/generate-password | ||
``` | ||
@@ -155,3 +154,3 @@ | ||
system.semver|n/a|semver | ||
internet.password|n/a|password -> `generate-password` funcs | ||
internet.password|n/a|password | ||
date.month|en,fr|month | ||
@@ -158,0 +157,0 @@ date.weekday|en,fr|weekday |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
834712
0.8%4
-20%19
5.56%55628
0.34%0
-100%163
-0.61%- Removed
- Removed
Updated