@poppinss/utils 6.8.3 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +1 -1
  2. package/build/chunk-2KG3PWR4.js +17 -0
  3. package/build/chunk-4V5ON6P7.js +7 -0
  4. package/build/chunk-EJKUJ44Y.js +12 -0
  5. package/build/chunk-H54AK3PI.js +7 -0
  6. package/build/{chunk-IOBSMUFC.js → chunk-XHQBV7AF.js} +0 -1
  7. package/build/index.d.ts +1 -2
  8. package/build/index.js +67 -68
  9. package/build/src/assert.js +2 -1
  10. package/build/src/base64.d.ts +2 -2
  11. package/build/src/exception.d.ts +1 -52
  12. package/build/src/exception.js +2 -2
  13. package/build/src/exceptions/main.d.ts +1 -2
  14. package/build/src/exceptions/main.js +2 -3
  15. package/build/src/json/main.js +2 -2
  16. package/build/src/object_builder.d.ts +1 -58
  17. package/build/src/slash.d.ts +24 -1
  18. package/build/src/slash.js +4 -4
  19. package/build/src/string/main.d.ts +1 -49
  20. package/build/src/string/main.js +2 -8
  21. package/build/src/string/string_builder.d.ts +1 -0
  22. package/build/src/string/string_builder.js +2 -0
  23. package/build/src/types.js +0 -1
  24. package/package.json +21 -26
  25. package/build/chunk-GGIWJLUJ.js +0 -55
  26. package/build/chunk-GGIWJLUJ.js.map +0 -1
  27. package/build/chunk-IOBSMUFC.js.map +0 -1
  28. package/build/chunk-K76IL3UP.js +0 -270
  29. package/build/chunk-K76IL3UP.js.map +0 -1
  30. package/build/chunk-NKGAOHNN.js +0 -64
  31. package/build/chunk-NKGAOHNN.js.map +0 -1
  32. package/build/chunk-PNT36FCE.js +0 -21
  33. package/build/chunk-PNT36FCE.js.map +0 -1
  34. package/build/chunk-RRTFLKKC.js +0 -7
  35. package/build/chunk-RRTFLKKC.js.map +0 -1
  36. package/build/index.js.map +0 -1
  37. package/build/src/assert.js.map +0 -1
  38. package/build/src/exception.js.map +0 -1
  39. package/build/src/exceptions/invalid_arguments_exception.d.ts +0 -5
  40. package/build/src/exceptions/main.js.map +0 -1
  41. package/build/src/exceptions/runtime_exception.d.ts +0 -5
  42. package/build/src/json/main.js.map +0 -1
  43. package/build/src/slash.js.map +0 -1
  44. package/build/src/string/bytes.d.ts +0 -11
  45. package/build/src/string/change_case.d.ts +0 -42
  46. package/build/src/string/excerpt.d.ts +0 -11
  47. package/build/src/string/interpolate.d.ts +0 -8
  48. package/build/src/string/main.js.map +0 -1
  49. package/build/src/string/milliseconds.d.ts +0 -9
  50. package/build/src/string/ordinal.d.ts +0 -4
  51. package/build/src/string/pluralize.d.ts +0 -16
  52. package/build/src/string/random.d.ts +0 -4
  53. package/build/src/string/seconds.d.ts +0 -9
  54. package/build/src/string/sentence.d.ts +0 -8
  55. package/build/src/string/slugify.d.ts +0 -6
  56. package/build/src/string/truncate.d.ts +0 -10
  57. package/build/src/string_builder.d.ts +0 -80
  58. package/build/src/string_builder.js +0 -149
  59. package/build/src/string_builder.js.map +0 -1
  60. package/build/src/types.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../index.ts","../src/secret.ts","../src/compose.ts","../src/import_default.ts","../src/define_static_property.ts","../src/flatten.ts","../src/fs_import_all.ts","../src/fs_read_all.ts","../src/natural_sort.ts","../src/is_script_file.ts","../src/message_builder.ts","../src/object_builder.ts","../src/safe_equal.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport { join as pathJoin, dirname as pathDirname } from 'node:path'\n\nexport { Secret } from './src/secret.js'\nexport { base64 } from './src/base64.js'\nexport { compose } from './src/compose.js'\nexport { importDefault } from './src/import_default.js'\nexport { defineStaticProperty } from './src/define_static_property.js'\nexport { Exception, createError } from './src/exception.js'\nexport { flatten } from './src/flatten.js'\nexport { fsImportAll } from './src/fs_import_all.js'\nexport { fsReadAll } from './src/fs_read_all.js'\nexport { isScriptFile } from './src/is_script_file.js'\nexport { MessageBuilder } from './src/message_builder.js'\nexport { naturalSort } from './src/natural_sort.js'\nexport { ObjectBuilder } from './src/object_builder.js'\nexport { safeEqual } from './src/safe_equal.js'\nexport { slash } from './src/slash.js'\nexport { RuntimeException } from './src/exceptions/runtime_exception.js'\nexport { InvalidArgumentsException } from './src/exceptions/invalid_arguments_exception.js'\n\n/**\n * Get dirname for a given file path URL\n */\nexport function getDirname(url: string | URL) {\n return pathDirname(getFilename(url))\n}\n\n/**\n * Get filename for a given file path URL\n */\nexport function getFilename(url: string | URL) {\n return fileURLToPath(url)\n}\n\n/**\n * Join paths to a URL instance or a URL string. The return\n * value will be a file path without the `file:///` protocol.\n */\nexport function joinToURL(url: string | URL, ...str: string[]) {\n return pathJoin(getDirname(url), ...str)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nconst REDACTED = '[redacted]'\n\n/**\n * Define a Secret value that hides itself from the logs or the console\n * statements.\n *\n * The idea is to prevent accidental leaking of sensitive information.\n * Idea borrowed from.\n * https://transcend.io/blog/keep-sensitive-values-out-of-your-logs-with-types\n */\nexport class Secret<T> {\n /** The secret value */\n #value: T\n #keyword: string\n\n constructor(value: T, redactedKeyword?: string) {\n this.#value = value\n this.#keyword = redactedKeyword || REDACTED\n }\n\n toJSON(): string {\n return this.#keyword\n }\n valueOf(): string {\n return this.#keyword\n }\n [Symbol.for('nodejs.util.inspect.custom')](): string {\n return this.#keyword\n }\n toLocaleString(): string {\n return this.#keyword\n }\n toString(): string {\n return this.#keyword\n }\n\n /**\n * Returns the original value\n */\n release(): T {\n return this.#value\n }\n\n /**\n * Transform the original value and create a new\n * secret from it.\n */\n map<R>(transformFunc: (value: T) => R): Secret<R> {\n return new Secret(transformFunc(this.#value))\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { Constructor } from './types.js'\n\ninterface UnaryFunction<T, R> {\n (source: T): R\n}\n\n/**\n * Compose a class by applying mixins to it.\n * The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its\n * just that I have added the support for static types too.\n */\nexport function compose<T extends Constructor, A>(superclass: T, mixin: UnaryFunction<T, A>): A\nexport function compose<T extends Constructor, A, B>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>\n): B\nexport function compose<T extends Constructor, A, B, C>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>\n): C\nexport function compose<T extends Constructor, A, B, C, D>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>\n): D\nexport function compose<T extends Constructor, A, B, C, D, E>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinE: UnaryFunction<D, E>\n): E\nexport function compose<T extends Constructor, A, B, C, D, E, F>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>\n): F\nexport function compose<T extends Constructor, A, B, C, D, E, F, G>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>,\n mixinG: UnaryFunction<F, G>\n): G\nexport function compose<T extends Constructor, A, B, C, D, E, F, G, H>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>,\n mixinG: UnaryFunction<F, G>,\n mixinH: UnaryFunction<G, H>\n): H\nexport function compose<T extends Constructor, A, B, C, D, E, F, G, H, I>(\n superclass: T,\n mixin: UnaryFunction<T, A>,\n mixinB: UnaryFunction<A, B>,\n mixinC: UnaryFunction<B, C>,\n mixinD: UnaryFunction<C, D>,\n mixinF: UnaryFunction<E, F>,\n mixinG: UnaryFunction<F, G>,\n mixinH: UnaryFunction<G, H>,\n mixinI: UnaryFunction<H, I>\n): I\nexport function compose<T extends Constructor, Mixins extends UnaryFunction<T, T>>(\n superclass: T,\n ...mixins: Mixins[]\n) {\n return mixins.reduce((c, mixin) => mixin(c), superclass)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { RuntimeException } from './exceptions/runtime_exception.js'\n\n/**\n * Dynamically import a module and ensure it has a default export\n */\nexport async function importDefault<T extends object>(\n importFn: () => Promise<T>,\n filePath?: string\n): Promise<T extends { default: infer A } ? A : never> {\n const moduleExports = await importFn()\n\n /**\n * Make sure a default export exists\n */\n if (!('default' in moduleExports)) {\n const errorMessage = filePath\n ? `Missing \"export default\" in module \"${filePath}\"`\n : `Missing \"export default\" from lazy import \"${importFn}\"`\n\n throw new RuntimeException(errorMessage, {\n cause: {\n source: importFn,\n },\n })\n }\n\n return moduleExports.default as Promise<T extends { default: infer A } ? A : never>\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport lodash from '@poppinss/utils/lodash'\n\ntype Constructor = new (...args: any[]) => any\ntype AbstractConstructor = abstract new (...args: any[]) => any\n\n/**\n * Define static properties on a class with inheritance in play.\n */\nexport function defineStaticProperty<\n T extends Constructor | AbstractConstructor,\n Prop extends keyof T,\n>(\n self: T,\n propertyName: Prop,\n {\n initialValue,\n strategy,\n }: {\n initialValue: T[Prop]\n strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop])\n }\n) {\n if (!self.hasOwnProperty(propertyName)) {\n const value = self[propertyName]\n\n /**\n * Define the property as it is when the strategy is set\n * to \"define\". Or the value on the prototype chain\n * is set to undefined.\n */\n if (strategy === 'define' || value === undefined) {\n Object.defineProperty(self, propertyName, {\n value: initialValue,\n configurable: true,\n enumerable: true,\n writable: true,\n })\n return\n }\n\n Object.defineProperty(self, propertyName, {\n value: typeof strategy === 'function' ? strategy(value) : lodash.cloneDeep(value),\n configurable: true,\n enumerable: true,\n writable: true,\n })\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { flattie } from 'flattie'\n\n/**\n * Recursively flatten an object/array.\n */\nexport function flatten<X = Record<string, any>, Y = unknown>(\n input: Y,\n glue?: string,\n keepNullish?: boolean\n): X {\n return flattie(input, glue, keepNullish)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport lodash from '@poppinss/utils/lodash'\nimport { extname, relative, sep } from 'node:path'\n\nimport { fsReadAll } from './fs_read_all.js'\nimport { ImportAllFilesOptions } from './types.js'\nimport { isScriptFile } from './is_script_file.js'\n\n/**\n * Import the file and update the values collection with the default\n * export.\n */\nasync function importFile(\n basePath: string,\n fileURL: string,\n values: any,\n options: ImportAllFilesOptions\n) {\n /**\n * Converting URL to file path\n */\n const filePath = fileURLToPath(fileURL)\n\n /**\n * Grab file extension\n */\n const fileExtension = extname(filePath)\n\n const collectionKey = relative(basePath, filePath) // Get file relative path\n .replace(new RegExp(`${fileExtension}$`), '') // Get rid of the file extension\n .split(sep) // Convert nested paths to an array of keys\n\n /**\n * Import module\n */\n const exportedValue =\n fileExtension === '.json'\n ? await import(fileURL, { with: { type: 'json' } })\n : await import(fileURL)\n\n lodash.set(\n values,\n options.transformKeys ? options.transformKeys(collectionKey) : collectionKey,\n exportedValue.default ? exportedValue.default : { ...exportedValue }\n )\n}\n\n/**\n * Returns an array of file paths from the given location. You can\n * optionally filter and sort files by passing relevant options\n *\n * ```ts\n * await fsReadAll(new URL('./', import.meta.url))\n *\n * await fsReadAll(new URL('./', import.meta.url), {\n * filter: (filePath) => filePath.endsWith('.js')\n * })\n\n * await fsReadAll(new URL('./', import.meta.url), {\n * absolute: true,\n * unixPaths: true\n * })\n* ```\n */\nexport async function fsImportAll(\n location: string | URL,\n options?: ImportAllFilesOptions\n): Promise<any> {\n options = options || {}\n const collection: any = {}\n const normalizedLocation = typeof location === 'string' ? location : fileURLToPath(location)\n const files = await fsReadAll(normalizedLocation, {\n filter: isScriptFile,\n ...options,\n pathType: 'url',\n })\n\n /**\n * Parallelly import all the files and mutate the values collection\n */\n await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options!)))\n\n return collection\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport { readdir, stat } from 'node:fs/promises'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { slash } from './slash.js'\nimport { naturalSort } from './natural_sort.js'\nimport { ReadAllFilesOptions } from './types.js'\n\n/**\n * Filter to remove dot files\n */\nfunction filterDotFiles(fileName: string) {\n return fileName[0] !== '.'\n}\n\n/**\n * Read all files from the directory recursively\n */\nasync function readFiles(\n root: string,\n files: string[],\n options: ReadAllFilesOptions,\n relativePath: string\n): Promise<void> {\n const location = join(root, relativePath)\n const stats = await stat(location)\n\n if (stats.isDirectory()) {\n let locationFiles = await readdir(location)\n\n await Promise.all(\n locationFiles.filter(filterDotFiles).map((file) => {\n return readFiles(root, files, options, join(relativePath, file))\n })\n )\n\n return\n }\n\n const pathType = options.pathType || 'relative'\n switch (pathType) {\n case 'relative':\n files.push(relativePath)\n break\n case 'absolute':\n files.push(location)\n break\n case 'unixRelative':\n files.push(slash(relativePath))\n break\n case 'unixAbsolute':\n files.push(slash(location))\n break\n case 'url':\n files.push(pathToFileURL(location).href)\n }\n}\n\n/**\n * Returns an array of file paths from the given location. You can\n * optionally filter and sort files by passing relevant options\n *\n * ```ts\n * await fsReadAll(new URL('./', import.meta.url))\n *\n * await fsReadAll(new URL('./', import.meta.url), {\n * filter: (filePath) => filePath.endsWith('.js')\n * })\n\n * await fsReadAll(new URL('./', import.meta.url), {\n * absolute: true,\n * unixPaths: true\n * })\n* ```\n */\nexport async function fsReadAll(\n location: string | URL,\n options?: ReadAllFilesOptions\n): Promise<string[]> {\n const normalizedLocation = typeof location === 'string' ? location : fileURLToPath(location)\n const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options)\n const files: string[] = []\n\n /**\n * Check to see if the root directory exists and ignore\n * error when \"ignoreMissingRoot\" is set to true\n */\n try {\n await stat(normalizedLocation)\n } catch (error) {\n if (normalizedOptions.ignoreMissingRoot) {\n return []\n }\n\n throw error\n }\n\n await readFiles(normalizedLocation, files, normalizedOptions, '')\n\n if (normalizedOptions.filter) {\n return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort)\n }\n\n return files.sort(normalizedOptions.sort)\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/**\n * Perform natural sorting with \"Array.sort()\" method\n */\nexport function naturalSort(current: string, next: string) {\n return current.localeCompare(next, undefined, { numeric: true, sensitivity: 'base' })\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { extname } from 'node:path'\nconst JS_MODULES = ['.js', '.json', '.cjs', '.mjs']\n\n/**\n * Returns `true` when file ends with `.js`, `.json` or\n * `.ts` but not `.d.ts`.\n */\nexport function isScriptFile(filePath: string) {\n const ext = extname(filePath)\n\n if (JS_MODULES.includes(ext)) {\n return true\n }\n\n if (ext === '.ts' && !filePath.endsWith('.d.ts')) {\n return true\n }\n\n return false\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport json from './json/main.js'\nimport milliseconds from './string/milliseconds.js'\n\n/**\n * Message builder exposes an API to \"JSON.stringify\" values by\n * encoding purpose and expiry date inside them.\n *\n * The return value must be further encrypted to prevent tempering.\n */\nexport class MessageBuilder {\n #getExpiryDate(expiresIn?: string | number): undefined | Date {\n if (!expiresIn) {\n return undefined\n }\n\n const expiryMs = milliseconds.parse(expiresIn)\n return new Date(Date.now() + expiryMs)\n }\n\n /**\n * Returns a boolean telling, if message has been expired or not\n */\n #isExpired(message: any) {\n if (!message.expiryDate) {\n return false\n }\n\n const expiryDate = new Date(message.expiryDate)\n return Number.isNaN(expiryDate.getTime()) || expiryDate < new Date()\n }\n\n /**\n * Builds a message by encoding expiry date and purpose inside it.\n */\n build(message: any, expiresIn?: string | number, purpose?: string): string {\n const expiryDate = this.#getExpiryDate(expiresIn)\n return json.safeStringify({ message, purpose, expiryDate })!\n }\n\n /**\n * Verifies the message for expiry and purpose.\n */\n verify<T extends any>(message: any, purpose?: string): null | T {\n const parsed = json.safeParse(message)\n\n /**\n * After JSON.parse we do not receive a valid object\n */\n if (typeof parsed !== 'object' || !parsed) {\n return null\n }\n\n /**\n * Missing \".message\" property\n */\n if (!parsed.message) {\n return null\n }\n\n /**\n * Ensure purposes are same.\n */\n if (parsed.purpose !== purpose) {\n return null\n }\n\n /**\n * Ensure isn't expired\n */\n if (this.#isExpired(parsed)) {\n return null\n }\n\n return parsed.message\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { OmitProperties } from './types.js'\n\n/**\n * A simple class to build an object incrementally. It is helpful when you\n * want to add properties to the object conditionally.\n *\n * Instead of writing\n * ```\n * const obj = {\n * ...(user.id ? { id: user.id } : {}),\n * ...(user.firstName && user.lastName ? { name: `${user.firstName} ${user.lastName}` } : {}),\n * }\n * ```\n *\n * You can write\n *\n * const obj = new ObjectBuilder()\n * .add('id', user.id)\n * .add(\n * 'fullName',\n * user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : undefined\n * )\n * .toObject()\n */\nexport class ObjectBuilder<\n ReturnType extends Record<string, any>,\n IgnoreNull extends boolean = false,\n> {\n #ignoreNull: boolean\n values: ReturnType\n\n constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull) {\n this.values = initialValue\n this.#ignoreNull = ignoreNull === true ? true : false\n }\n\n /**\n * Add a key-value pair to the object\n *\n * - Undefined values are ignored\n * - Null values are ignored, when `ignoreNull` is set to true\n */\n add<Prop extends string>(key: Prop, value: undefined): this\n add<Prop extends string, Value>(\n key: Prop,\n value: Value\n ): ObjectBuilder<ReturnType & { [P in Prop]: Value }, IgnoreNull>\n add<Prop extends string, Value>(key: Prop, value: Value): this {\n if (value === undefined) {\n return this\n }\n\n if (this.#ignoreNull === true && value === null) {\n return this\n }\n\n ;(this.values as any)[key] = value\n return this\n }\n\n /**\n * Remove key from the object\n */\n remove<K extends keyof ReturnType>(key: K): this {\n delete this.values[key]\n return this\n }\n\n /**\n * Find if a value exists\n */\n has<K extends keyof ReturnType>(key: K): boolean {\n return this.get(key) !== undefined\n }\n\n /**\n * Get the existing value for a given key\n */\n get<K extends keyof ReturnType>(key: K): ReturnType[K] {\n return this.values[key]\n }\n\n /**\n * Get the underlying constructed object\n */\n toObject(): IgnoreNull extends true\n ? { [K in keyof OmitProperties<ReturnType, null>]: ReturnType[K] }\n : { [K in keyof ReturnType]: ReturnType[K] } {\n return this.values\n }\n}\n","/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Buffer } from 'node:buffer'\nimport { timingSafeEqual } from 'node:crypto'\n\ntype BufferSafeValue =\n | ArrayBuffer\n | SharedArrayBuffer\n | number[]\n | string\n | { valueOf(): string | object }\n | { [Symbol.toPrimitive](hint: 'string'): string }\n\n/**\n * Compare two values to see if they are equal. The comparison is done in\n * a way to avoid timing-attacks.\n */\nexport function safeEqual<T extends BufferSafeValue, U extends BufferSafeValue>(\n trustedValue: T,\n userInput: U\n): boolean {\n if (typeof trustedValue === 'string' && typeof userInput === 'string') {\n /**\n * The length of the comparison value.\n */\n const trustedLength = Buffer.byteLength(trustedValue)\n\n /**\n * Expected value\n */\n const trustedValueBuffer = Buffer.alloc(trustedLength, 0, 'utf-8')\n trustedValueBuffer.write(trustedValue)\n\n /**\n * Actual value (taken from user input)\n */\n const userValueBuffer = Buffer.alloc(trustedLength, 0, 'utf-8')\n userValueBuffer.write(userInput)\n\n /**\n * Ensure values are same and also have same length\n */\n return (\n timingSafeEqual(trustedValueBuffer, userValueBuffer) &&\n trustedLength === Buffer.byteLength(userInput)\n )\n }\n\n return timingSafeEqual(\n Buffer.from(trustedValue as ArrayBuffer | SharedArrayBuffer),\n Buffer.from(userInput as ArrayBuffer | SharedArrayBuffer)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AASA,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,QAAQ,UAAU,WAAW,mBAAmB;;;ACDzD,IAAM,WAAW;AAUV,IAAM,SAAN,MAAM,QAAU;AAAA;AAAA,EAErB;AAAA,EACA;AAAA,EAEA,YAAY,OAAU,iBAA0B;AAC9C,SAAK,SAAS;AACd,SAAK,WAAW,mBAAmB;AAAA,EACrC;AAAA,EAEA,SAAiB;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EACA,UAAkB;AAChB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,CAAC,OAAO,IAAI,4BAA4B,CAAC,IAAY;AACnD,WAAO,KAAK;AAAA,EACd;AAAA,EACA,iBAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EACA,WAAmB;AACjB,WAAO,K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B;AAC7C,SAAOG,eAAc,GAAG;AAC1B;AAMO,SAAS,UAAU,QAAsB,KAAe;AAC7D,SAAO,SAAS,WAAW,GAAG,GAAG,GAAG,GAAG;AACzC;","names":["fileURLToPath","fileURLToPath","lodash","extname","default","fileURLToPath","extname","lodash","fileURLToPath"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/assert.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { inspect } from 'node:util'\nimport { AssertionError } from 'node:assert'\n\n/**\n * @alias \"assertExists\"\n */\nexport function assert(value: unknown, message?: string): asserts value {\n return assertExists(value, message)\n}\n\n/**\n * Assert the value is turthy or raise an exception.\n *\n * Truthy value excludes, undefined, null, and false values.\n */\nexport function assertExists(value: unknown, message?: string): asserts value {\n if (!value) {\n throw new AssertionError({ message: message ?? 'value is falsy' })\n }\n}\n\n/**\n * Throws error when method is called\n */\nexport function assertUnreachable(x?: never): never {\n throw new AssertionError({ message: `unreachable code executed: ${inspect(x)}` })\n}\n\n/**\n * Assert the value is not null.\n */\nexport function assertNotNull<T>(\n value: T | null,\n message?: string\n): asserts value is Exclude<T, null> {\n if (value === null) {\n throw new AssertionError({ message: message ?? 'unexpected null value' })\n }\n}\n\n/**\n * Assert the value is not undefined.\n */\nexport function assertIsDefined<T>(\n value: T | undefined,\n message?: string\n): asserts value is Exclude<T, undefined> {\n if (value === undefined) {\n throw new AssertionError({ message: message ?? 'unexpected undefined value' })\n }\n}\n"],"mappings":";AASA,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAKxB,SAAS,OAAO,OAAgB,SAAiC;AACtE,SAAO,aAAa,OAAO,OAAO;AACpC;AAOO,SAAS,aAAa,OAAgB,SAAiC;AAC5E,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,eAAe,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACnE;AACF;AAKO,SAAS,kBAAkB,GAAkB;AAClD,QAAM,IAAI,eAAe,EAAE,SAAS,8BAA8B,QAAQ,CAAC,CAAC,GAAG,CAAC;AAClF;AAKO,SAAS,cACd,OACA,SACmC;AACnC,MAAI,UAAU,MAAM;AAClB,UAAM,IAAI,eAAe,EAAE,SAAS,WAAW,wBAAwB,CAAC;AAAA,EAC1E;AACF;AAKO,SAAS,gBACd,OACA,SACwC;AACxC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,eAAe,EAAE,SAAS,WAAW,6BAA6B,CAAC;AAAA,EAC/E;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +0,0 @@
1
- import { Exception } from '../exception.js';
2
- export declare class InvalidArgumentsException extends Exception {
3
- static code: string;
4
- static status: number;
5
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +0,0 @@
1
- import { Exception } from '../exception.js';
2
- export declare class RuntimeException extends Exception {
3
- static code: string;
4
- static status: number;
5
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,11 +0,0 @@
1
- import { BytesOptions } from 'bytes';
2
- declare const _default: {
3
- format(valueInBytes: number, options?: BytesOptions): string;
4
- /**
5
- * Parse the unit expression to bytes. If the unit value
6
- * is a number, then it will be returned as it is considering
7
- * it is already in bytes.
8
- */
9
- parse(unit: string | number): number;
10
- };
11
- export default _default;
@@ -1,42 +0,0 @@
1
- /**
2
- * The method is a copy/paste from the "title-case" package. They have
3
- * a dependency on "tslib", which I don't want.
4
- */
5
- export declare function titleCase(input: string): string;
6
- /**
7
- * Convert string to camelcase
8
- */
9
- export declare function camelCase(value: string): string;
10
- /**
11
- * Convert string to snakecase
12
- */
13
- export declare function snakeCase(value: string): string;
14
- /**
15
- * Convert string to dashcase
16
- */
17
- export declare function dashCase(value: string, options?: {
18
- capitalize?: boolean;
19
- }): string;
20
- /**
21
- * Convert string to pascal case
22
- */
23
- export declare function pascalCase(value: string): string;
24
- /**
25
- * Convert string to capital case
26
- */
27
- export declare function capitalCase(value: string): string;
28
- /**
29
- * Convert string to sentence case
30
- */
31
- export declare function sentenceCase(value: string): string;
32
- /**
33
- * Convert string to dot case
34
- */
35
- export declare function dotCase(value: string, options?: {
36
- lowerCase?: boolean;
37
- }): string;
38
- /**
39
- * Remove all sort of casing from the string. Copy-pasted from
40
- * "no-case" package with slight modifications.
41
- */
42
- export declare function noCase(value: string, transform?: (part: string, index: number, parts: string[]) => string): string;
@@ -1,11 +0,0 @@
1
- /**
2
- * Truncate a sentence to be under a certain characters limit and strip
3
- * out HTML tags from it.
4
- *
5
- * Optionally, you can force the truncate logic to complete words, which
6
- * may exceed the defined characters limit.
7
- */
8
- export declare function excerpt(sentence: string, charactersLimit: number, options?: {
9
- completeWords?: boolean;
10
- suffix?: string;
11
- }): string;
@@ -1,8 +0,0 @@
1
- /**
2
- * A simple function interpolate values inside curly braces.
3
- *
4
- * ```
5
- * interpolate('hello {{ username }}', { username: 'virk' })
6
- * ```
7
- */
8
- export declare function interpolate(input: string, data: any): string;
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,9 +0,0 @@
1
- declare const _default: {
2
- format(milliseconds: number, long?: boolean): string;
3
- /**
4
- * Parse time expression string to milliseconds. The number value
5
- * is returned as it is, considering it is already in milliseconds
6
- */
7
- parse(duration: string | number): number;
8
- };
9
- export default _default;
@@ -1,4 +0,0 @@
1
- /**
2
- * Ordinalize a give number or string
3
- */
4
- export declare function ordinal(value: string | number): string;
@@ -1,16 +0,0 @@
1
- import { default as pluralizePkg } from 'pluralize';
2
- /**
3
- * Pluralize a word based upon the count. The method returns the
4
- * singular form when count is 1.
5
- */
6
- export declare function pluralize(word: string, count?: number, inclusive?: boolean): string;
7
- export declare namespace pluralize {
8
- var addPluralRule: typeof pluralizePkg.addPluralRule;
9
- var addSingularRule: typeof pluralizePkg.addSingularRule;
10
- var addIrregularRule: typeof pluralizePkg.addIrregularRule;
11
- var addUncountableRule: typeof pluralizePkg.addUncountableRule;
12
- }
13
- export declare const plural: typeof pluralizePkg.plural;
14
- export declare const singular: typeof pluralizePkg.singular;
15
- export declare const isPlural: typeof pluralizePkg.isPlural;
16
- export declare const isSingular: typeof pluralizePkg.isSingular;
@@ -1,4 +0,0 @@
1
- /**
2
- * Generates a random string of a given size
3
- */
4
- export declare function random(size: number): string;
@@ -1,9 +0,0 @@
1
- declare const _default: {
2
- format(seconds: number, long?: boolean): string;
3
- /**
4
- * Parse time expression string to seconds. The number value
5
- * is returned as it is, considering it is already in seconds
6
- */
7
- parse(duration: string | number): number;
8
- };
9
- export default _default;
@@ -1,8 +0,0 @@
1
- /**
2
- * Convert an array of values to a sentence.
3
- */
4
- export declare function sentence(values: any[], options?: {
5
- separator?: string;
6
- pairSeparator?: string;
7
- lastSeparator?: string;
8
- }): string;
@@ -1,6 +0,0 @@
1
- import { default as slugifyPkg } from 'slugify';
2
- /**
3
- * Typings of the slugify package are a bit off and therefore we have
4
- * to do this manual dance of re-assigning types
5
- */
6
- export declare const slug: (typeof slugifyPkg)["default"];
@@ -1,10 +0,0 @@
1
- /**
2
- * Truncate a sentence to be under a certain characters limit.
3
- *
4
- * Optionally, you can force the truncate logic to complete words, which
5
- * may exceed the defined characters limit.
6
- */
7
- export declare function truncate(sentence: string, charactersLimit: number, options?: {
8
- completeWords?: boolean;
9
- suffix?: string;
10
- }): string;
@@ -1,80 +0,0 @@
1
- /**
2
- * String builder to transform the string using the fluent API
3
- */
4
- export default class StringBuilder {
5
- #private;
6
- constructor(value: string | StringBuilder);
7
- /**
8
- * Applies dash case transformation
9
- */
10
- dashCase(): this;
11
- /**
12
- * Applies dot case transformation
13
- */
14
- dotCase(): this;
15
- /**
16
- * Applies snake case transformation
17
- */
18
- snakeCase(): this;
19
- /**
20
- * Applies pascal case transformation
21
- */
22
- pascalCase(): this;
23
- /**
24
- * Applies camelcase case transformation
25
- */
26
- camelCase(): this;
27
- /**
28
- * Applies capital case transformation
29
- */
30
- capitalCase(): this;
31
- /**
32
- * Applies title case transformation
33
- */
34
- titleCase(): this;
35
- /**
36
- * Applies sentence case transformation
37
- */
38
- sentenceCase(): this;
39
- /**
40
- * Removes all sorts of casing from the string
41
- */
42
- noCase(): this;
43
- /**
44
- * Converts value to its plural form
45
- */
46
- plural(): this;
47
- /**
48
- * Converts value to its singular form
49
- */
50
- singular(): this;
51
- /**
52
- * Converts value to a URL friendly slug
53
- */
54
- slugify(): this;
55
- /**
56
- * Removes a given suffix from the string
57
- */
58
- removeSuffix(suffix: string): this;
59
- /**
60
- * Adds suffix to the string
61
- */
62
- suffix(suffix: string): this;
63
- /**
64
- * Removes a given prefix from the string
65
- */
66
- removePrefix(prefix: string): this;
67
- /**
68
- * Adds prefix to the string
69
- */
70
- prefix(prefix: string): this;
71
- /**
72
- * Removes extension from the value
73
- */
74
- removeExtension(): this;
75
- /**
76
- * Adds extension to the value
77
- */
78
- ext(extension: string): this;
79
- toString(): string;
80
- }
@@ -1,149 +0,0 @@
1
- import {
2
- main_default
3
- } from "../chunk-K76IL3UP.js";
4
- import "../chunk-NKGAOHNN.js";
5
-
6
- // src/string_builder.ts
7
- import { extname } from "node:path";
8
- var StringBuilder = class {
9
- #value;
10
- constructor(value) {
11
- this.#value = typeof value === "string" ? value : value.toString();
12
- }
13
- /**
14
- * Applies dash case transformation
15
- */
16
- dashCase() {
17
- this.#value = main_default.dashCase(this.#value);
18
- return this;
19
- }
20
- /**
21
- * Applies dot case transformation
22
- */
23
- dotCase() {
24
- this.#value = main_default.dotCase(this.#value);
25
- return this;
26
- }
27
- /**
28
- * Applies snake case transformation
29
- */
30
- snakeCase() {
31
- this.#value = main_default.snakeCase(this.#value);
32
- return this;
33
- }
34
- /**
35
- * Applies pascal case transformation
36
- */
37
- pascalCase() {
38
- this.#value = main_default.pascalCase(this.#value);
39
- return this;
40
- }
41
- /**
42
- * Applies camelcase case transformation
43
- */
44
- camelCase() {
45
- this.#value = main_default.camelCase(this.#value);
46
- return this;
47
- }
48
- /**
49
- * Applies capital case transformation
50
- */
51
- capitalCase() {
52
- this.#value = main_default.capitalCase(this.#value);
53
- return this;
54
- }
55
- /**
56
- * Applies title case transformation
57
- */
58
- titleCase() {
59
- this.#value = main_default.titleCase(this.#value);
60
- return this;
61
- }
62
- /**
63
- * Applies sentence case transformation
64
- */
65
- sentenceCase() {
66
- this.#value = main_default.sentenceCase(this.#value);
67
- return this;
68
- }
69
- /**
70
- * Removes all sorts of casing from the string
71
- */
72
- noCase() {
73
- this.#value = main_default.noCase(this.#value);
74
- return this;
75
- }
76
- /**
77
- * Converts value to its plural form
78
- */
79
- plural() {
80
- this.#value = main_default.pluralize(this.#value);
81
- return this;
82
- }
83
- /**
84
- * Converts value to its singular form
85
- */
86
- singular() {
87
- this.#value = main_default.singular(this.#value);
88
- return this;
89
- }
90
- /**
91
- * Converts value to a URL friendly slug
92
- */
93
- slugify() {
94
- this.#value = main_default.slug(this.#value);
95
- return this;
96
- }
97
- /**
98
- * Removes a given suffix from the string
99
- */
100
- removeSuffix(suffix) {
101
- this.#value = this.#value.replace(new RegExp(`[-_]?${suffix}$`, "i"), "");
102
- return this;
103
- }
104
- /**
105
- * Adds suffix to the string
106
- */
107
- suffix(suffix) {
108
- this.removeSuffix(suffix);
109
- this.#value = `${this.#value}${suffix}`;
110
- return this;
111
- }
112
- /**
113
- * Removes a given prefix from the string
114
- */
115
- removePrefix(prefix) {
116
- this.#value = this.#value.replace(new RegExp(`^${prefix}[-_]?`, "i"), "");
117
- return this;
118
- }
119
- /**
120
- * Adds prefix to the string
121
- */
122
- prefix(prefix) {
123
- this.removePrefix(prefix);
124
- this.#value = `${prefix}${this.#value}`;
125
- return this;
126
- }
127
- /**
128
- * Removes extension from the value
129
- */
130
- removeExtension() {
131
- this.#value = this.#value.replace(new RegExp(`${extname(this.#value)}$`), "");
132
- return this;
133
- }
134
- /**
135
- * Adds extension to the value
136
- */
137
- ext(extension) {
138
- this.removeExtension();
139
- this.#value = `${this.#value}.${extension.replace(/^\./, "")}`;
140
- return this;
141
- }
142
- toString() {
143
- return this.#value;
144
- }
145
- };
146
- export {
147
- StringBuilder as default
148
- };
149
- //# sourceMappingURL=string_builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/string_builder.ts"],"sourcesContent":["/*\n * @poppinss/utils\n *\n * (c) Poppinss\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { extname } from 'node:path'\nimport string from './string/main.js'\n\n/**\n * String builder to transform the string using the fluent API\n */\nexport default class StringBuilder {\n #value: string\n\n constructor(value: string | StringBuilder) {\n this.#value = typeof value === 'string' ? value : value.toString()\n }\n\n /**\n * Applies dash case transformation\n */\n dashCase(): this {\n this.#value = string.dashCase(this.#value)\n return this\n }\n\n /**\n * Applies dot case transformation\n */\n dotCase(): this {\n this.#value = string.dotCase(this.#value)\n return this\n }\n\n /**\n * Applies snake case transformation\n */\n snakeCase(): this {\n this.#value = string.snakeCase(this.#value)\n return this\n }\n\n /**\n * Applies pascal case transformation\n */\n pascalCase(): this {\n this.#value = string.pascalCase(this.#value)\n return this\n }\n\n /**\n * Applies camelcase case transformation\n */\n camelCase(): this {\n this.#value = string.camelCase(this.#value)\n return this\n }\n\n /**\n * Applies capital case transformation\n */\n capitalCase(): this {\n this.#value = string.capitalCase(this.#value)\n return this\n }\n\n /**\n * Applies title case transformation\n */\n titleCase(): this {\n this.#value = string.titleCase(this.#value)\n return this\n }\n\n /**\n * Applies sentence case transformation\n */\n sentenceCase(): this {\n this.#value = string.sentenceCase(this.#value)\n return this\n }\n\n /**\n * Removes all sorts of casing from the string\n */\n noCase(): this {\n this.#value = string.noCase(this.#value)\n return this\n }\n\n /**\n * Converts value to its plural form\n */\n plural(): this {\n this.#value = string.pluralize(this.#value)\n return this\n }\n\n /**\n * Converts value to its singular form\n */\n singular(): this {\n this.#value = string.singular(this.#value)\n return this\n }\n\n /**\n * Converts value to a URL friendly slug\n */\n slugify(): this {\n this.#value = string.slug(this.#value)\n return this\n }\n\n /**\n * Removes a given suffix from the string\n */\n removeSuffix(suffix: string): this {\n this.#value = this.#value.replace(new RegExp(`[-_]?${suffix}$`, 'i'), '')\n return this\n }\n\n /**\n * Adds suffix to the string\n */\n suffix(suffix: string): this {\n this.removeSuffix(suffix)\n this.#value = `${this.#value}${suffix}`\n return this\n }\n\n /**\n * Removes a given prefix from the string\n */\n removePrefix(prefix: string): this {\n this.#value = this.#value.replace(new RegExp(`^${prefix}[-_]?`, 'i'), '')\n return this\n }\n\n /**\n * Adds prefix to the string\n */\n prefix(prefix: string): this {\n this.removePrefix(prefix)\n this.#value = `${prefix}${this.#value}`\n return this\n }\n\n /**\n * Removes extension from the value\n */\n removeExtension(): this {\n this.#value = this.#value.replace(new RegExp(`${extname(this.#value)}$`), '')\n return this\n }\n\n /**\n * Adds extension to the value\n */\n ext(extension: string): this {\n this.removeExtension()\n this.#value = `${this.#value}.${extension.replace(/^\\./, '')}`\n return this\n }\n\n toString() {\n return this.#value\n }\n}\n"],"mappings":";;;;;;AASA,SAAS,eAAe;AAMxB,IAAqB,gBAArB,MAAmC;AAAA,EACjC;AAAA,EAEA,YAAY,OAA+B;AACzC,SAAK,SAAS,OAAO,UAAU,WAAW,QAAQ,MAAM,SAAS;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAKA,WAAiB;AACf,SAAK,SAAS,aAAO,SAAS,KAAK,MAAM;AACzC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,UAAgB;AACd,SAAK,SAAS,aAAO,QAAQ,KAAK,MAAM;AACxC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,YAAkB;AAChB,SAAK,SAAS,aAAO,UAAU,KAAK,MAAM;AAC1C,WAAO;AAAA,E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