@vielzeug/toolkit 1.0.12 → 1.0.14

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 (166) hide show
  1. package/dist/array/{sortBy.cjs → arrange.cjs} +2 -2
  2. package/dist/array/arrange.cjs.map +1 -0
  3. package/dist/array/arrange.js +6 -0
  4. package/dist/array/arrange.js.map +1 -0
  5. package/dist/array/chunk.cjs +1 -1
  6. package/dist/array/chunk.cjs.map +1 -1
  7. package/dist/array/chunk.js +15 -12
  8. package/dist/array/chunk.js.map +1 -1
  9. package/dist/array/group.cjs +1 -1
  10. package/dist/array/group.cjs.map +1 -1
  11. package/dist/array/group.js +9 -9
  12. package/dist/array/group.js.map +1 -1
  13. package/dist/array/list.cjs +1 -1
  14. package/dist/array/list.cjs.map +1 -1
  15. package/dist/array/list.js +87 -50
  16. package/dist/array/list.js.map +1 -1
  17. package/dist/array/pick.cjs.map +1 -1
  18. package/dist/array/pick.js.map +1 -1
  19. package/dist/array/remoteList.cjs +2 -0
  20. package/dist/array/remoteList.cjs.map +1 -0
  21. package/dist/array/remoteList.js +123 -0
  22. package/dist/array/remoteList.js.map +1 -0
  23. package/dist/date/expires.cjs.map +1 -1
  24. package/dist/date/expires.js.map +1 -1
  25. package/dist/date/interval.cjs.map +1 -1
  26. package/dist/date/interval.js.map +1 -1
  27. package/dist/date/timeDiff.cjs +1 -1
  28. package/dist/date/timeDiff.cjs.map +1 -1
  29. package/dist/date/timeDiff.js +10 -12
  30. package/dist/date/timeDiff.js.map +1 -1
  31. package/dist/function/curry.cjs +1 -1
  32. package/dist/function/curry.cjs.map +1 -1
  33. package/dist/function/curry.js +3 -3
  34. package/dist/function/curry.js.map +1 -1
  35. package/dist/function/debounce.cjs +1 -1
  36. package/dist/function/debounce.cjs.map +1 -1
  37. package/dist/function/debounce.js +22 -5
  38. package/dist/function/debounce.js.map +1 -1
  39. package/dist/function/memo.cjs +1 -1
  40. package/dist/function/memo.cjs.map +1 -1
  41. package/dist/function/memo.js +14 -13
  42. package/dist/function/memo.js.map +1 -1
  43. package/dist/function/parallel.cjs +2 -0
  44. package/dist/function/parallel.cjs.map +1 -0
  45. package/dist/function/parallel.js +28 -0
  46. package/dist/function/parallel.js.map +1 -0
  47. package/dist/function/proxy.cjs.map +1 -1
  48. package/dist/function/proxy.js.map +1 -1
  49. package/dist/function/prune.cjs +2 -0
  50. package/dist/function/prune.cjs.map +1 -0
  51. package/dist/function/prune.js +30 -0
  52. package/dist/function/prune.js.map +1 -0
  53. package/dist/function/retry.cjs +1 -1
  54. package/dist/function/retry.cjs.map +1 -1
  55. package/dist/function/retry.js +13 -13
  56. package/dist/function/retry.js.map +1 -1
  57. package/dist/function/sleep.cjs +1 -1
  58. package/dist/function/sleep.cjs.map +1 -1
  59. package/dist/function/sleep.js +8 -3
  60. package/dist/function/sleep.js.map +1 -1
  61. package/dist/function/throttle.cjs +1 -1
  62. package/dist/function/throttle.cjs.map +1 -1
  63. package/dist/function/throttle.js +33 -6
  64. package/dist/function/throttle.js.map +1 -1
  65. package/dist/index.cjs +1 -1
  66. package/dist/index.d.ts +455 -95
  67. package/dist/index.js +218 -194
  68. package/dist/index.js.map +1 -1
  69. package/dist/math/abs.cjs +2 -0
  70. package/dist/math/abs.cjs.map +1 -0
  71. package/dist/math/abs.js +7 -0
  72. package/dist/math/abs.js.map +1 -0
  73. package/dist/math/add.cjs +2 -0
  74. package/dist/math/add.cjs.map +1 -0
  75. package/dist/math/add.js +9 -0
  76. package/dist/math/add.js.map +1 -0
  77. package/dist/math/allocate.cjs +2 -0
  78. package/dist/math/allocate.cjs.map +1 -0
  79. package/dist/math/allocate.js +29 -0
  80. package/dist/math/allocate.js.map +1 -0
  81. package/dist/math/average.cjs +1 -1
  82. package/dist/math/average.cjs.map +1 -1
  83. package/dist/math/average.js +18 -12
  84. package/dist/math/average.js.map +1 -1
  85. package/dist/math/distribute.cjs +2 -0
  86. package/dist/math/distribute.cjs.map +1 -0
  87. package/dist/math/distribute.js +18 -0
  88. package/dist/math/distribute.js.map +1 -0
  89. package/dist/math/divide.cjs +2 -0
  90. package/dist/math/divide.cjs.map +1 -0
  91. package/dist/math/divide.js +11 -0
  92. package/dist/math/divide.js.map +1 -0
  93. package/dist/math/median.cjs.map +1 -1
  94. package/dist/math/median.js.map +1 -1
  95. package/dist/math/multiply.cjs +2 -0
  96. package/dist/math/multiply.cjs.map +1 -0
  97. package/dist/math/multiply.js +9 -0
  98. package/dist/math/multiply.js.map +1 -0
  99. package/dist/math/range.cjs +1 -1
  100. package/dist/math/range.cjs.map +1 -1
  101. package/dist/math/range.js +14 -6
  102. package/dist/math/range.js.map +1 -1
  103. package/dist/math/subtract.cjs +2 -0
  104. package/dist/math/subtract.cjs.map +1 -0
  105. package/dist/math/subtract.js +9 -0
  106. package/dist/math/subtract.js.map +1 -0
  107. package/dist/math/sum.cjs +1 -1
  108. package/dist/math/sum.cjs.map +1 -1
  109. package/dist/math/sum.js +11 -18
  110. package/dist/math/sum.js.map +1 -1
  111. package/dist/money/currency.cjs +2 -0
  112. package/dist/money/currency.cjs.map +1 -0
  113. package/dist/money/currency.js +49 -0
  114. package/dist/money/currency.js.map +1 -0
  115. package/dist/money/exchange.cjs +2 -0
  116. package/dist/money/exchange.cjs.map +1 -0
  117. package/dist/money/exchange.js +13 -0
  118. package/dist/money/exchange.js.map +1 -0
  119. package/dist/object/clone.cjs +1 -1
  120. package/dist/object/clone.cjs.map +1 -1
  121. package/dist/object/clone.js +13 -3
  122. package/dist/object/clone.js.map +1 -1
  123. package/dist/object/merge.cjs +1 -1
  124. package/dist/object/merge.cjs.map +1 -1
  125. package/dist/object/merge.js +11 -15
  126. package/dist/object/merge.js.map +1 -1
  127. package/dist/object/parseJSON.cjs.map +1 -1
  128. package/dist/object/parseJSON.js.map +1 -1
  129. package/dist/object/path.cjs.map +1 -1
  130. package/dist/object/path.js.map +1 -1
  131. package/dist/object/seek.cjs +1 -1
  132. package/dist/object/seek.cjs.map +1 -1
  133. package/dist/object/seek.js +8 -6
  134. package/dist/object/seek.js.map +1 -1
  135. package/dist/random/uuid.cjs +1 -1
  136. package/dist/random/uuid.cjs.map +1 -1
  137. package/dist/random/uuid.js +6 -3
  138. package/dist/random/uuid.js.map +1 -1
  139. package/dist/string/camelCase.cjs +1 -1
  140. package/dist/string/camelCase.cjs.map +1 -1
  141. package/dist/string/camelCase.js +3 -3
  142. package/dist/string/camelCase.js.map +1 -1
  143. package/dist/string/similarity.cjs +1 -1
  144. package/dist/string/similarity.cjs.map +1 -1
  145. package/dist/string/similarity.js +24 -21
  146. package/dist/string/similarity.js.map +1 -1
  147. package/dist/string/truncate.cjs +1 -1
  148. package/dist/string/truncate.cjs.map +1 -1
  149. package/dist/string/truncate.js +14 -5
  150. package/dist/string/truncate.js.map +1 -1
  151. package/dist/typed/is.cjs +1 -1
  152. package/dist/typed/is.cjs.map +1 -1
  153. package/dist/typed/is.js +30 -31
  154. package/dist/typed/is.js.map +1 -1
  155. package/dist/typed/isEmpty.cjs +1 -1
  156. package/dist/typed/isEmpty.cjs.map +1 -1
  157. package/dist/typed/isEmpty.js +6 -6
  158. package/dist/typed/isEmpty.js.map +1 -1
  159. package/dist/typed/isEqual.cjs +1 -1
  160. package/dist/typed/isEqual.cjs.map +1 -1
  161. package/dist/typed/isEqual.js +22 -17
  162. package/dist/typed/isEqual.js.map +1 -1
  163. package/package.json +1 -1
  164. package/dist/array/sortBy.cjs.map +0 -1
  165. package/dist/array/sortBy.js +0 -6
  166. package/dist/array/sortBy.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"parseJSON.cjs","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\ninterface ParseJSONOptions<T> {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n}\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":"8LAoCO,SAASA,EAA+BC,EAAeC,EAA+B,GAAmB,CAC9G,KAAM,CAAE,aAAAC,EAAc,QAAAC,EAAS,UAAAC,EAAW,OAAAC,EAAS,IAAUJ,EAE7D,GAAI,CAACK,EAAAA,SAASN,CAAI,SAAUO,EAAAA,MAAMP,CAAI,EAAIE,EAAgBF,EAE1D,GAAI,CACF,MAAMQ,EAAS,KAAK,MAAMR,EAAgBG,CAAO,EAEjD,GAAIC,GAAa,CAACA,EAAUI,CAAM,EAChC,MAAM,IAAI,UAAU,mDAAmD,EAGzE,OAAOA,GAAUN,CACnB,OAASO,EAAK,CACZ,OAAKJ,GACHK,QAAM,MAAM,wCAAyCD,CAAG,EAGnDP,CACT,CACF"}
1
+ {"version":3,"file":"parseJSON.cjs","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\n// #region ParseJSONOptions\ntype ParseJSONOptions<T> = {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n};\n// #endregion ParseJSONOptions\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":"8LAsCO,SAASA,EAA+BC,EAAeC,EAA+B,GAAmB,CAC9G,KAAM,CAAE,aAAAC,EAAc,QAAAC,EAAS,UAAAC,EAAW,OAAAC,EAAS,IAAUJ,EAE7D,GAAI,CAACK,EAAAA,SAASN,CAAI,SAAUO,EAAAA,MAAMP,CAAI,EAAIE,EAAgBF,EAE1D,GAAI,CACF,MAAMQ,EAAS,KAAK,MAAMR,EAAgBG,CAAO,EAEjD,GAAIC,GAAa,CAACA,EAAUI,CAAM,EAChC,MAAM,IAAI,UAAU,mDAAmD,EAGzE,OAAOA,GAAUN,CACnB,OAASO,EAAK,CACZ,OAAKJ,GACHK,QAAM,MAAM,wCAAyCD,CAAG,EAGnDP,CACT,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseJSON.js","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\ninterface ParseJSONOptions<T> {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n}\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":";;;AAoCO,SAASA,EAA+BC,GAAeC,IAA+B,IAAmB;AAC9G,QAAM,EAAE,cAAAC,GAAc,SAAAC,GAAS,WAAAC,GAAW,QAAAC,IAAS,OAAUJ;AAE7D,MAAI,CAACK,EAASN,CAAI,UAAUO,EAAMP,CAAI,IAAIE,IAAgBF;AAE1D,MAAI;AACF,UAAMQ,IAAS,KAAK,MAAMR,GAAgBG,CAAO;AAEjD,QAAIC,KAAa,CAACA,EAAUI,CAAM;AAChC,YAAM,IAAI,UAAU,mDAAmD;AAGzE,WAAOA,KAAUN;AAAA,EACnB,SAASO,GAAK;AACZ,WAAKJ,KACHK,EAAM,MAAM,yCAAyCD,CAAG,GAGnDP;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"parseJSON.js","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\n// #region ParseJSONOptions\ntype ParseJSONOptions<T> = {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n};\n// #endregion ParseJSONOptions\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":";;;AAsCO,SAASA,EAA+BC,GAAeC,IAA+B,IAAmB;AAC9G,QAAM,EAAE,cAAAC,GAAc,SAAAC,GAAS,WAAAC,GAAW,QAAAC,IAAS,OAAUJ;AAE7D,MAAI,CAACK,EAASN,CAAI,UAAUO,EAAMP,CAAI,IAAIE,IAAgBF;AAE1D,MAAI;AACF,UAAMQ,IAAS,KAAK,MAAMR,GAAgBG,CAAO;AAEjD,QAAIC,KAAa,CAACA,EAAUI,CAAM;AAChC,YAAM,IAAI,UAAU,mDAAmD;AAGzE,WAAOA,KAAUN;AAAA,EACnB,SAASO,GAAK;AACZ,WAAKJ,KACHK,EAAM,MAAM,yCAAyCD,CAAG,GAGnDP;AAAA,EACT;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"path.cjs","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":"+NA2CO,SAASA,EACdC,EACAD,EACAE,EACAC,EAAuB,CAAA,EACM,CAC7BC,EAAAA,OAAOC,EAAAA,SAASJ,CAAI,EAAGK,sBAAqB,CAAE,KAAM,CAAE,KAAAL,CAAA,EAAQ,KAAM,UAAW,EAE/E,KAAM,CAAE,eAAAM,EAAiB,GAAO,gBAAAC,EAAkB,IAAUL,EAEtDM,EAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO,EAEtD,IAAIU,EAAeT,EAEnB,UAAWU,KAAYF,EAAW,CAChC,GAAIG,EAAAA,MAAMF,CAAO,GAAK,OAAOA,GAAY,SACvC,OAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,GAAIH,EAAgBL,CAAY,EAMrG,GAHAQ,EACEF,GAAmBM,EAAAA,QAAQJ,CAAO,GAAK,QAAQ,KAAKC,CAAQ,EAAID,EAAQ,OAAOC,CAAQ,CAAC,EAAID,EAAQC,CAAQ,EAE1GD,IAAY,OACd,OAAOG,EAAY,aAAaF,CAAQ,mBAAoBJ,EAAgBL,CAAY,CAE5F,CAEA,OAAOQ,CACT,CAEA,SAASG,EACPE,EACAR,EACAL,EAC6B,CAC7B,GAAIK,EAAgB,MAAM,IAAI,MAAMQ,CAAO,EAC3C,OAAOb,CACT"}
1
+ {"version":3,"file":"path.cjs","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\n// #region PathOptions\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n// #endregion PathOptions\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":"+NA6CO,SAASA,EACdC,EACAD,EACAE,EACAC,EAAuB,CAAA,EACM,CAC7BC,EAAAA,OAAOC,EAAAA,SAASJ,CAAI,EAAGK,sBAAqB,CAAE,KAAM,CAAE,KAAAL,CAAA,EAAQ,KAAM,UAAW,EAE/E,KAAM,CAAE,eAAAM,EAAiB,GAAO,gBAAAC,EAAkB,IAAUL,EAEtDM,EAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO,EAEtD,IAAIU,EAAeT,EAEnB,UAAWU,KAAYF,EAAW,CAChC,GAAIG,EAAAA,MAAMF,CAAO,GAAK,OAAOA,GAAY,SACvC,OAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,GAAIH,EAAgBL,CAAY,EAMrG,GAHAQ,EACEF,GAAmBM,EAAAA,QAAQJ,CAAO,GAAK,QAAQ,KAAKC,CAAQ,EAAID,EAAQ,OAAOC,CAAQ,CAAC,EAAID,EAAQC,CAAQ,EAE1GD,IAAY,OACd,OAAOG,EAAY,aAAaF,CAAQ,mBAAoBJ,EAAgBL,CAAY,CAE5F,CAEA,OAAOQ,CACT,CAEA,SAASG,EACPE,EACAR,EACAL,EAC6B,CAC7B,GAAIK,EAAgB,MAAM,IAAI,MAAMQ,CAAO,EAC3C,OAAOb,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":";;;;AA2CO,SAASA,EACdC,GACAD,GACAE,GACAC,IAAuB,CAAA,GACM;AAC7B,EAAAC,EAAOC,EAASJ,CAAI,GAAGK,GAAqB,EAAE,MAAM,EAAE,MAAAL,EAAA,GAAQ,MAAM,WAAW;AAE/E,QAAM,EAAE,gBAAAM,IAAiB,IAAO,iBAAAC,IAAkB,OAAUL,GAEtDM,IAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO;AAEtD,MAAIU,IAAeT;AAEnB,aAAWU,KAAYF,GAAW;AAChC,QAAIG,EAAMF,CAAO,KAAK,OAAOA,KAAY;AACvC,aAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,IAAIH,GAAgBL,CAAY;AAMrG,QAHAQ,IACEF,KAAmBM,EAAQJ,CAAO,KAAK,QAAQ,KAAKC,CAAQ,IAAID,EAAQ,OAAOC,CAAQ,CAAC,IAAID,EAAQC,CAAQ,GAE1GD,MAAY;AACd,aAAOG,EAAY,aAAaF,CAAQ,oBAAoBJ,GAAgBL,CAAY;AAAA,EAE5F;AAEA,SAAOQ;AACT;AAEA,SAASG,EACPE,GACAR,GACAL,GAC6B;AAC7B,MAAIK,EAAgB,OAAM,IAAI,MAAMQ,CAAO;AAC3C,SAAOb;AACT;"}
1
+ {"version":3,"file":"path.js","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\n// #region PathOptions\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n// #endregion PathOptions\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":";;;;AA6CO,SAASA,EACdC,GACAD,GACAE,GACAC,IAAuB,CAAA,GACM;AAC7B,EAAAC,EAAOC,EAASJ,CAAI,GAAGK,GAAqB,EAAE,MAAM,EAAE,MAAAL,EAAA,GAAQ,MAAM,WAAW;AAE/E,QAAM,EAAE,gBAAAM,IAAiB,IAAO,iBAAAC,IAAkB,OAAUL,GAEtDM,IAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO;AAEtD,MAAIU,IAAeT;AAEnB,aAAWU,KAAYF,GAAW;AAChC,QAAIG,EAAMF,CAAO,KAAK,OAAOA,KAAY;AACvC,aAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,IAAIH,GAAgBL,CAAY;AAMrG,QAHAQ,IACEF,KAAmBM,EAAQJ,CAAO,KAAK,QAAQ,KAAKC,CAAQ,IAAID,EAAQ,OAAOC,CAAQ,CAAC,IAAID,EAAQC,CAAQ,GAE1GD,MAAY;AACd,aAAOG,EAAY,aAAaF,CAAQ,oBAAoBJ,GAAgBL,CAAY;AAAA,EAE5F;AAEA,SAAOQ;AACT;AAEA,SAASG,EACPE,GACAR,GACAL,GAC6B;AAC7B,MAAIK,EAAgB,OAAM,IAAI,MAAMQ,CAAO;AAC3C,SAAOb;AACT;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../function/assert.cjs"),c=require("../string/similarity.cjs"),s=require("../typed/is.cjs"),o=require("../typed/isWithin.cjs");function a(e,t,i=1){return f.assert(o.isWithin(i,0,1),o.IS_WITHIN_ERROR_MSG,{args:{max:1,min:0,tone:i},type:TypeError}),s.is("string",e)||s.is("number",e)?c.similarity(e,t)>=i:Object.values(e).some(r=>s.is("nil",r)?!1:s.is("array",r)?r.some(n=>s.is("object",n)?a(n,t,i):c.similarity(n,t)>=i):s.is("object",r)?a(r,t,i):c.similarity(r,t)>=i)}exports.seek=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../function/assert.cjs"),l=require("../string/similarity.cjs"),s=require("../typed/is.cjs"),a=require("../typed/isWithin.cjs");function t(r,n,i=1){return u.assert(a.isWithin(i,0,1),a.IS_WITHIN_ERROR_MSG,{args:{max:1,min:0,tone:i},type:TypeError}),s.is("nil",r)?!1:s.is("string",r)||s.is("number",r)?l.similarity(r,n)>=i:s.is("array",r)?r.some(e=>t(e,n,i)):s.is("object",r)?Object.values(r).some(e=>s.is("nil",e)?!1:t(e,n,i)):!1}exports.seek=t;
2
2
  //# sourceMappingURL=seek.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"seek.cjs","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n return Object.values(item as Record<string, unknown>).some((value) => {\n if (is('nil', value)) return false;\n\n if (is('array', value)) {\n return value.some((v) => (is('object', v) ? seek(v, query, tone) : similarity(v, query) >= tone));\n }\n\n if (is('object', value)) {\n return seek(value, query, tone);\n }\n\n return similarity(value, query) >= tone;\n });\n}\n"],"names":["seek","item","query","tone","assert","isWithin","IS_WITHIN_ERROR_MSG","is","similarity","value","v"],"mappings":"gOA6BO,SAASA,EAAQC,EAASC,EAAeC,EAAO,EAAY,CAGjE,OAFAC,EAAAA,OAAOC,EAAAA,SAASF,EAAM,EAAG,CAAC,EAAGG,EAAAA,oBAAqB,CAAE,KAAM,CAAE,IAAK,EAAG,IAAK,EAAG,KAAAH,GAAQ,KAAM,UAAW,EAEjGI,EAAAA,GAAG,SAAUN,CAAI,GAAKM,EAAAA,GAAG,SAAUN,CAAI,EAElCO,aAAWP,EAAMC,CAAK,GAAKC,EAG7B,OAAO,OAAOF,CAA+B,EAAE,KAAMQ,GACtDF,KAAG,MAAOE,CAAK,EAAU,GAEzBF,EAAAA,GAAG,QAASE,CAAK,EACZA,EAAM,KAAMC,GAAOH,EAAAA,GAAG,SAAUG,CAAC,EAAIV,EAAKU,EAAGR,EAAOC,CAAI,EAAIK,EAAAA,WAAWE,EAAGR,CAAK,GAAKC,CAAK,EAG9FI,EAAAA,GAAG,SAAUE,CAAK,EACbT,EAAKS,EAAOP,EAAOC,CAAI,EAGzBK,aAAWC,EAAOP,CAAK,GAAKC,CACpC,CACH"}
1
+ {"version":3,"file":"seek.cjs","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('nil', item)) return false;\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n // Handle arrays\n if (is('array', item)) {\n return (item as unknown[]).some((value) => seek(value, query, tone));\n }\n\n // Handle objects but skip dates/regex/etc which are technically objects\n if (is('object', item)) {\n return Object.values(item as Record<string, unknown>).some((value) =>\n is('nil', value) ? false : seek(value, query, tone),\n );\n }\n\n return false;\n}\n"],"names":["seek","item","query","tone","assert","isWithin","IS_WITHIN_ERROR_MSG","is","similarity","value"],"mappings":"gOA6BO,SAASA,EAAQC,EAASC,EAAeC,EAAO,EAAY,CAGjE,OAFAC,EAAAA,OAAOC,EAAAA,SAASF,EAAM,EAAG,CAAC,EAAGG,EAAAA,oBAAqB,CAAE,KAAM,CAAE,IAAK,EAAG,IAAK,EAAG,KAAAH,GAAQ,KAAM,UAAW,EAEjGI,KAAG,MAAON,CAAI,EAAU,GAExBM,EAAAA,GAAG,SAAUN,CAAI,GAAKM,EAAAA,GAAG,SAAUN,CAAI,EAElCO,aAAWP,EAAMC,CAAK,GAAKC,EAIhCI,EAAAA,GAAG,QAASN,CAAI,EACVA,EAAmB,KAAMQ,GAAUT,EAAKS,EAAOP,EAAOC,CAAI,CAAC,EAIjEI,EAAAA,GAAG,SAAUN,CAAI,EACZ,OAAO,OAAOA,CAA+B,EAAE,KAAMQ,GAC1DF,KAAG,MAAOE,CAAK,EAAI,GAAQT,EAAKS,EAAOP,EAAOC,CAAI,CAAA,EAI/C,EACT"}
@@ -1,11 +1,13 @@
1
- import { assert as p } from "../function/assert.js";
2
- import { similarity as o } from "../string/similarity.js";
1
+ import { assert as n } from "../function/assert.js";
2
+ import { similarity as m } from "../string/similarity.js";
3
3
  import { is as s } from "../typed/is.js";
4
- import { IS_WITHIN_ERROR_MSG as b, isWithin as c } from "../typed/isWithin.js";
5
- function n(t, m, r = 1) {
6
- return p(c(r, 0, 1), b, { args: { max: 1, min: 0, tone: r }, type: TypeError }), s("string", t) || s("number", t) ? o(t, m) >= r : Object.values(t).some((i) => s("nil", i) ? !1 : s("array", i) ? i.some((f) => s("object", f) ? n(f, m, r) : o(f, m) >= r) : s("object", i) ? n(i, m, r) : o(i, m) >= r);
4
+ import { IS_WITHIN_ERROR_MSG as p, isWithin as t } from "../typed/isWithin.js";
5
+ function a(r, o, i = 1) {
6
+ return n(t(i, 0, 1), p, { args: { max: 1, min: 0, tone: i }, type: TypeError }), s("nil", r) ? !1 : s("string", r) || s("number", r) ? m(r, o) >= i : s("array", r) ? r.some((f) => a(f, o, i)) : s("object", r) ? Object.values(r).some(
7
+ (f) => s("nil", f) ? !1 : a(f, o, i)
8
+ ) : !1;
7
9
  }
8
10
  export {
9
- n as seek
11
+ a as seek
10
12
  };
11
13
  //# sourceMappingURL=seek.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seek.js","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n return Object.values(item as Record<string, unknown>).some((value) => {\n if (is('nil', value)) return false;\n\n if (is('array', value)) {\n return value.some((v) => (is('object', v) ? seek(v, query, tone) : similarity(v, query) >= tone));\n }\n\n if (is('object', value)) {\n return seek(value, query, tone);\n }\n\n return similarity(value, query) >= tone;\n });\n}\n"],"names":["seek","item","query","tone","assert","isWithin","IS_WITHIN_ERROR_MSG","is","similarity","value","v"],"mappings":";;;;AA6BO,SAASA,EAAQC,GAASC,GAAeC,IAAO,GAAY;AAGjE,SAFAC,EAAOC,EAASF,GAAM,GAAG,CAAC,GAAGG,GAAqB,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAAH,KAAQ,MAAM,WAAW,GAEjGI,EAAG,UAAUN,CAAI,KAAKM,EAAG,UAAUN,CAAI,IAElCO,EAAWP,GAAMC,CAAK,KAAKC,IAG7B,OAAO,OAAOF,CAA+B,EAAE,KAAK,CAACQ,MACtDF,EAAG,OAAOE,CAAK,IAAU,KAEzBF,EAAG,SAASE,CAAK,IACZA,EAAM,KAAK,CAACC,MAAOH,EAAG,UAAUG,CAAC,IAAIV,EAAKU,GAAGR,GAAOC,CAAI,IAAIK,EAAWE,GAAGR,CAAK,KAAKC,CAAK,IAG9FI,EAAG,UAAUE,CAAK,IACbT,EAAKS,GAAOP,GAAOC,CAAI,IAGzBK,EAAWC,GAAOP,CAAK,KAAKC,CACpC;AACH;"}
1
+ {"version":3,"file":"seek.js","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('nil', item)) return false;\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n // Handle arrays\n if (is('array', item)) {\n return (item as unknown[]).some((value) => seek(value, query, tone));\n }\n\n // Handle objects but skip dates/regex/etc which are technically objects\n if (is('object', item)) {\n return Object.values(item as Record<string, unknown>).some((value) =>\n is('nil', value) ? false : seek(value, query, tone),\n );\n }\n\n return false;\n}\n"],"names":["seek","item","query","tone","assert","isWithin","IS_WITHIN_ERROR_MSG","is","similarity","value"],"mappings":";;;;AA6BO,SAASA,EAAQC,GAASC,GAAeC,IAAO,GAAY;AAGjE,SAFAC,EAAOC,EAASF,GAAM,GAAG,CAAC,GAAGG,GAAqB,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAAH,KAAQ,MAAM,WAAW,GAEjGI,EAAG,OAAON,CAAI,IAAU,KAExBM,EAAG,UAAUN,CAAI,KAAKM,EAAG,UAAUN,CAAI,IAElCO,EAAWP,GAAMC,CAAK,KAAKC,IAIhCI,EAAG,SAASN,CAAI,IACVA,EAAmB,KAAK,CAACQ,MAAUT,EAAKS,GAAOP,GAAOC,CAAI,CAAC,IAIjEI,EAAG,UAAUN,CAAI,IACZ,OAAO,OAAOA,CAA+B,EAAE;AAAA,IAAK,CAACQ,MAC1DF,EAAG,OAAOE,CAAK,IAAI,KAAQT,EAAKS,GAAOP,GAAOC,CAAI;AAAA,EAAA,IAI/C;AACT;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(){return crypto?.randomUUID()??[12,6,6,6,18].map(t=>Math.floor(Math.random()*10**t).toString(36)).join("-")}exports.uuid=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/x/g,r=>{const x=Math.random()*16|0;return(r==="x"?x:x&3|8).toString(16)})}exports.uuid=t;
2
2
  //# sourceMappingURL=uuid.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.cjs","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n return (\n crypto?.randomUUID() ?? [12, 6, 6, 6, 18].map((val) => Math.floor(Math.random() * 10 ** val).toString(36)).join('-')\n );\n}\n"],"names":["uuid","val"],"mappings":"gFAUO,SAASA,GAAe,CAC7B,OACE,QAAQ,cAAgB,CAAC,GAAI,EAAG,EAAG,EAAG,EAAE,EAAE,IAAKC,GAAQ,KAAK,MAAM,KAAK,OAAA,EAAW,IAAMA,CAAG,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,CAEvH"}
1
+ {"version":3,"file":"uuid.cjs","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n\n return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/x/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"],"names":["uuid","c","r"],"mappings":"gFAUO,SAASA,GAAe,CAC7B,OAAI,OAAO,OAAW,KAAe,OAAO,WACnC,OAAO,WAAA,EAGT,uCAAuC,QAAQ,KAAOC,GAAM,CACjE,MAAMC,EAAK,KAAK,OAAA,EAAW,GAAM,EAEjC,OADUD,IAAM,IAAMC,EAAKA,EAAI,EAAO,GAC7B,SAAS,EAAE,CACtB,CAAC,CACH"}
@@ -1,7 +1,10 @@
1
- function r() {
2
- return crypto?.randomUUID() ?? [12, 6, 6, 6, 18].map((o) => Math.floor(Math.random() * 10 ** o).toString(36)).join("-");
1
+ function n() {
2
+ return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/x/g, (r) => {
3
+ const x = Math.random() * 16 | 0;
4
+ return (r === "x" ? x : x & 3 | 8).toString(16);
5
+ });
3
6
  }
4
7
  export {
5
- r as uuid
8
+ n as uuid
6
9
  };
7
10
  //# sourceMappingURL=uuid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.js","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n return (\n crypto?.randomUUID() ?? [12, 6, 6, 6, 18].map((val) => Math.floor(Math.random() * 10 ** val).toString(36)).join('-')\n );\n}\n"],"names":["uuid","val"],"mappings":"AAUO,SAASA,IAAe;AAC7B,SACE,QAAQ,gBAAgB,CAAC,IAAI,GAAG,GAAG,GAAG,EAAE,EAAE,IAAI,CAACC,MAAQ,KAAK,MAAM,KAAK,OAAA,IAAW,MAAMA,CAAG,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG;AAEvH;"}
1
+ {"version":3,"file":"uuid.js","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n\n return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/x/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"],"names":["uuid","c","r"],"mappings":"AAUO,SAASA,IAAe;AAC7B,SAAI,OAAO,SAAW,OAAe,OAAO,aACnC,OAAO,WAAA,IAGT,uCAAuC,QAAQ,MAAM,CAACC,MAAM;AACjE,UAAMC,IAAK,KAAK,OAAA,IAAW,KAAM;AAEjC,YADUD,MAAM,MAAMC,IAAKA,IAAI,IAAO,GAC7B,SAAS,EAAE;AAAA,EACtB,CAAC;AACH;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./_caseUtils.cjs");function t(a){return s.normalizeCase(a," ").replace(/(?:^|\s)(\w)/g,(e,r)=>r.toUpperCase()).replace(/\s+/g,"").replace(/^./,e=>e.toLowerCase())}exports.camelCase=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./_caseUtils.cjs");function o(a){return t.normalizeCase(a," ").replace(/[^a-zA-Z0-9]+(.)/g,(e,r)=>r.toUpperCase()).replace(/^./,e=>e.toLowerCase())}exports.camelCase=o;
2
2
  //# sourceMappingURL=camelCase.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"camelCase.cjs","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/(?:^|\\s)(\\w)/g, (_, char) => char.toUpperCase())\n .replace(/\\s+/g, '')\n .replace(/^./, (char) => char.toLowerCase());\n}\n"],"names":["camelCase","str","normalizeCase","_","char"],"mappings":"oHAcO,SAASA,EAAUC,EAAqB,CAC7C,OAAOC,EAAAA,cAAcD,EAAK,GAAG,EAC1B,QAAQ,gBAAiB,CAACE,EAAGC,IAASA,EAAK,YAAA,CAAa,EACxD,QAAQ,OAAQ,EAAE,EAClB,QAAQ,KAAOA,GAASA,EAAK,aAAa,CAC/C"}
1
+ {"version":3,"file":"camelCase.cjs","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()) // Basic split by non-alphanumeric\n .replace(/^./, (char) => char.toLowerCase());\n}\n"],"names":["camelCase","str","normalizeCase","_","char"],"mappings":"oHAcO,SAASA,EAAUC,EAAqB,CAC7C,OAAOC,EAAAA,cAAcD,EAAK,GAAG,EAC1B,QAAQ,oBAAqB,CAACE,EAAGC,IAASA,EAAK,YAAA,CAAa,EAC5D,QAAQ,KAAOA,GAASA,EAAK,aAAa,CAC/C"}
@@ -1,8 +1,8 @@
1
1
  import { normalizeCase as o } from "./_caseUtils.js";
2
- function s(r) {
3
- return o(r, " ").replace(/(?:^|\s)(\w)/g, (e, a) => a.toUpperCase()).replace(/\s+/g, "").replace(/^./, (e) => e.toLowerCase());
2
+ function t(r) {
3
+ return o(r, " ").replace(/[^a-zA-Z0-9]+(.)/g, (e, a) => a.toUpperCase()).replace(/^./, (e) => e.toLowerCase());
4
4
  }
5
5
  export {
6
- s as camelCase
6
+ t as camelCase
7
7
  };
8
8
  //# sourceMappingURL=camelCase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"camelCase.js","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/(?:^|\\s)(\\w)/g, (_, char) => char.toUpperCase())\n .replace(/\\s+/g, '')\n .replace(/^./, (char) => char.toLowerCase());\n}\n"],"names":["camelCase","str","normalizeCase","_","char"],"mappings":";AAcO,SAASA,EAAUC,GAAqB;AAC7C,SAAOC,EAAcD,GAAK,GAAG,EAC1B,QAAQ,iBAAiB,CAACE,GAAGC,MAASA,EAAK,YAAA,CAAa,EACxD,QAAQ,QAAQ,EAAE,EAClB,QAAQ,MAAM,CAACA,MAASA,EAAK,aAAa;AAC/C;"}
1
+ {"version":3,"file":"camelCase.js","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()) // Basic split by non-alphanumeric\n .replace(/^./, (char) => char.toLowerCase());\n}\n"],"names":["camelCase","str","normalizeCase","_","char"],"mappings":";AAcO,SAASA,EAAUC,GAAqB;AAC7C,SAAOC,EAAcD,GAAK,GAAG,EAC1B,QAAQ,qBAAqB,CAACE,GAAGC,MAASA,EAAK,YAAA,CAAa,EAC5D,QAAQ,MAAM,CAACA,MAASA,EAAK,aAAa;AAC/C;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../function/assert.cjs");function u(a,c){g.assert(["string","number"].includes(typeof a)&&["string","number"].includes(typeof c),"Invalid arguments",{args:{str1:a,str2:c},type:TypeError});const r=String(a).toLowerCase(),i=String(c).toLowerCase();if(r===i)return 1;if(!r.length||!i.length)return 0;const o=r.length,s=i.length,n=Array.from({length:o+1},(t,e)=>[e]);for(let t=0;t<=s;t++)n[0][t]=t;for(let t=1;t<=o;t++)for(let e=1;e<=s;e++){const l=r[t-1]===i[e-1]?0:1;n[t][e]=Math.min(n[t-1][e]+1,n[t][e-1]+1,n[t-1][e-1]+l)}return 1-n[o][s]/Math.max(o,s)}exports.similarity=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../function/assert.cjs");function y(l,g){f.assert(["string","number"].includes(typeof l)&&["string","number"].includes(typeof g),"Invalid arguments",{args:{str1:l,str2:g},type:TypeError});const n=String(l).toLowerCase(),t=String(g).toLowerCase();if(n===t)return 1;if(n.length===0)return t.length===0?1:0;if(t.length===0)return 0;const[a,c]=n.length<t.length?[n,t]:[t,n],s=a.length,h=c.length;let r=Array.from({length:s+1},(i,e)=>e),o=new Array(s+1);for(let i=1;i<=h;i++){o[0]=i;for(let e=1;e<=s;e++){const u=c[i-1]===a[e-1]?0:1;o[e]=Math.min(o[e-1]+1,r[e]+1,r[e-1]+u)}[r,o]=[o,r]}return 1-r[s]/Math.max(n.length,t.length)}exports.similarity=y;
2
2
  //# sourceMappingURL=similarity.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"similarity.cjs","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (!a.length || !b.length) return 0;\n\n const aLength = a.length;\n const bLength = b.length;\n\n // Initialize matrix with first row and column\n const matrix: number[][] = Array.from({ length: aLength + 1 }, (_, i) => [i]);\n for (let j = 0; j <= bLength; j++) {\n matrix[0][j] = j;\n }\n\n // Calculate Levenshtein distance\n for (let i = 1; i <= aLength; i++) {\n for (let j = 1; j <= bLength; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n matrix[i][j] = Math.min(\n matrix[i - 1][j] + 1, // deletion\n matrix[i][j - 1] + 1, // insertion\n matrix[i - 1][j - 1] + cost, // substitution\n );\n }\n }\n\n const distance = matrix[aLength][bLength];\n\n return 1 - distance / Math.max(aLength, bLength);\n}\n"],"names":["similarity","str1","str2","assert","a","b","aLength","bLength","matrix","_","i","j","cost"],"mappings":"0HAoBO,SAASA,EAAWC,EAAeC,EAAuB,CAC/DC,EAAAA,OACE,CAAC,SAAU,QAAQ,EAAE,SAAS,OAAOF,CAAI,GAAK,CAAC,SAAU,QAAQ,EAAE,SAAS,OAAOC,CAAI,EACvF,oBACA,CACE,KAAM,CAAE,KAAAD,EAAM,KAAAC,CAAA,EACd,KAAM,SAAA,CACR,EAGF,MAAME,EAAI,OAAOH,CAAI,EAAE,YAAA,EACjBI,EAAI,OAAOH,CAAI,EAAE,YAAA,EAEvB,GAAIE,IAAMC,EAAG,MAAO,GACpB,GAAI,CAACD,EAAE,QAAU,CAACC,EAAE,OAAQ,MAAO,GAEnC,MAAMC,EAAUF,EAAE,OACZG,EAAUF,EAAE,OAGZG,EAAqB,MAAM,KAAK,CAAE,OAAQF,EAAU,CAAA,EAAK,CAACG,EAAGC,IAAM,CAACA,CAAC,CAAC,EAC5E,QAASC,EAAI,EAAGA,GAAKJ,EAASI,IAC5BH,EAAO,CAAC,EAAEG,CAAC,EAAIA,EAIjB,QAASD,EAAI,EAAGA,GAAKJ,EAASI,IAC5B,QAASC,EAAI,EAAGA,GAAKJ,EAASI,IAAK,CACjC,MAAMC,EAAOR,EAAEM,EAAI,CAAC,IAAML,EAAEM,EAAI,CAAC,EAAI,EAAI,EACzCH,EAAOE,CAAC,EAAEC,CAAC,EAAI,KAAK,IAClBH,EAAOE,EAAI,CAAC,EAAEC,CAAC,EAAI,EACnBH,EAAOE,CAAC,EAAEC,EAAI,CAAC,EAAI,EACnBH,EAAOE,EAAI,CAAC,EAAEC,EAAI,CAAC,EAAIC,CAAA,CAE3B,CAKF,MAAO,GAFUJ,EAAOF,CAAO,EAAEC,CAAO,EAElB,KAAK,IAAID,EAASC,CAAO,CACjD"}
1
+ {"version":3,"file":"similarity.cjs","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (a.length === 0) return b.length === 0 ? 1 : 0;\n if (b.length === 0) return 0;\n\n // Swap to ensure we use the smaller string for columns (O(min(A,B)) space)\n const [shorter, longer] = a.length < b.length ? [a, b] : [b, a];\n const shorterLength = shorter.length;\n const longerLength = longer.length;\n\n let prevRow = Array.from({ length: shorterLength + 1 }, (_, i) => i);\n let currRow = new Array(shorterLength + 1);\n\n for (let i = 1; i <= longerLength; i++) {\n currRow[0] = i;\n for (let j = 1; j <= shorterLength; j++) {\n const cost = longer[i - 1] === shorter[j - 1] ? 0 : 1;\n currRow[j] = Math.min(\n currRow[j - 1] + 1, // insertion\n prevRow[j] + 1, // deletion\n prevRow[j - 1] + cost, // substitution\n );\n }\n // Swap rows for the next iteration (avoid allocation)\n [prevRow, currRow] = [currRow, prevRow];\n }\n\n // After the loop, a result is in prevRow because of the swap\n const distance = prevRow[shorterLength];\n\n return 1 - distance / Math.max(a.length, b.length);\n}\n"],"names":["similarity","str1","str2","assert","a","b","shorter","longer","shorterLength","longerLength","prevRow","_","i","currRow","j","cost"],"mappings":"0HAoBO,SAASA,EAAWC,EAAeC,EAAuB,CAC/DC,EAAAA,OACE,CAAC,SAAU,QAAQ,EAAE,SAAS,OAAOF,CAAI,GAAK,CAAC,SAAU,QAAQ,EAAE,SAAS,OAAOC,CAAI,EACvF,oBACA,CACE,KAAM,CAAE,KAAAD,EAAM,KAAAC,CAAA,EACd,KAAM,SAAA,CACR,EAGF,MAAME,EAAI,OAAOH,CAAI,EAAE,YAAA,EACjBI,EAAI,OAAOH,CAAI,EAAE,YAAA,EAEvB,GAAIE,IAAMC,EAAG,MAAO,GACpB,GAAID,EAAE,SAAW,SAAUC,EAAE,SAAW,EAAI,EAAI,EAChD,GAAIA,EAAE,SAAW,EAAG,MAAO,GAG3B,KAAM,CAACC,EAASC,CAAM,EAAIH,EAAE,OAASC,EAAE,OAAS,CAACD,EAAGC,CAAC,EAAI,CAACA,EAAGD,CAAC,EACxDI,EAAgBF,EAAQ,OACxBG,EAAeF,EAAO,OAE5B,IAAIG,EAAU,MAAM,KAAK,CAAE,OAAQF,EAAgB,GAAK,CAACG,EAAGC,IAAMA,CAAC,EAC/DC,EAAU,IAAI,MAAML,EAAgB,CAAC,EAEzC,QAAS,EAAI,EAAG,GAAKC,EAAc,IAAK,CACtCI,EAAQ,CAAC,EAAI,EACb,QAASC,EAAI,EAAGA,GAAKN,EAAeM,IAAK,CACvC,MAAMC,EAAOR,EAAO,EAAI,CAAC,IAAMD,EAAQQ,EAAI,CAAC,EAAI,EAAI,EACpDD,EAAQC,CAAC,EAAI,KAAK,IAChBD,EAAQC,EAAI,CAAC,EAAI,EACjBJ,EAAQI,CAAC,EAAI,EACbJ,EAAQI,EAAI,CAAC,EAAIC,CAAA,CAErB,CAEA,CAACL,EAASG,CAAO,EAAI,CAACA,EAASH,CAAO,CACxC,CAKA,MAAO,GAFUA,EAAQF,CAAa,EAEhB,KAAK,IAAIJ,EAAE,OAAQC,EAAE,MAAM,CACnD"}
@@ -1,34 +1,37 @@
1
- import { assert as l } from "../function/assert.js";
2
- function h(a, c) {
3
- l(
4
- ["string", "number"].includes(typeof a) && ["string", "number"].includes(typeof c),
1
+ import { assert as f } from "../function/assert.js";
2
+ function y(i, s) {
3
+ f(
4
+ ["string", "number"].includes(typeof i) && ["string", "number"].includes(typeof s),
5
5
  "Invalid arguments",
6
6
  {
7
- args: { str1: a, str2: c },
7
+ args: { str1: i, str2: s },
8
8
  type: TypeError
9
9
  }
10
10
  );
11
- const r = String(a).toLowerCase(), o = String(c).toLowerCase();
12
- if (r === o) return 1;
13
- if (!r.length || !o.length) return 0;
14
- const i = r.length, s = o.length, e = Array.from({ length: i + 1 }, (t, n) => [n]);
15
- for (let t = 0; t <= s; t++)
16
- e[0][t] = t;
17
- for (let t = 1; t <= i; t++)
18
- for (let n = 1; n <= s; n++) {
19
- const g = r[t - 1] === o[n - 1] ? 0 : 1;
20
- e[t][n] = Math.min(
21
- e[t - 1][n] + 1,
22
- // deletion
23
- e[t][n - 1] + 1,
11
+ const n = String(i).toLowerCase(), e = String(s).toLowerCase();
12
+ if (n === e) return 1;
13
+ if (n.length === 0) return e.length === 0 ? 1 : 0;
14
+ if (e.length === 0) return 0;
15
+ const [h, a] = n.length < e.length ? [n, e] : [e, n], l = h.length, c = a.length;
16
+ let r = Array.from({ length: l + 1 }, (g, t) => t), o = new Array(l + 1);
17
+ for (let g = 1; g <= c; g++) {
18
+ o[0] = g;
19
+ for (let t = 1; t <= l; t++) {
20
+ const u = a[g - 1] === h[t - 1] ? 0 : 1;
21
+ o[t] = Math.min(
22
+ o[t - 1] + 1,
24
23
  // insertion
25
- e[t - 1][n - 1] + g
24
+ r[t] + 1,
25
+ // deletion
26
+ r[t - 1] + u
26
27
  // substitution
27
28
  );
28
29
  }
29
- return 1 - e[i][s] / Math.max(i, s);
30
+ [r, o] = [o, r];
31
+ }
32
+ return 1 - r[l] / Math.max(n.length, e.length);
30
33
  }
31
34
  export {
32
- h as similarity
35
+ y as similarity
33
36
  };
34
37
  //# sourceMappingURL=similarity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"similarity.js","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (!a.length || !b.length) return 0;\n\n const aLength = a.length;\n const bLength = b.length;\n\n // Initialize matrix with first row and column\n const matrix: number[][] = Array.from({ length: aLength + 1 }, (_, i) => [i]);\n for (let j = 0; j <= bLength; j++) {\n matrix[0][j] = j;\n }\n\n // Calculate Levenshtein distance\n for (let i = 1; i <= aLength; i++) {\n for (let j = 1; j <= bLength; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n matrix[i][j] = Math.min(\n matrix[i - 1][j] + 1, // deletion\n matrix[i][j - 1] + 1, // insertion\n matrix[i - 1][j - 1] + cost, // substitution\n );\n }\n }\n\n const distance = matrix[aLength][bLength];\n\n return 1 - distance / Math.max(aLength, bLength);\n}\n"],"names":["similarity","str1","str2","assert","a","b","aLength","bLength","matrix","_","i","j","cost"],"mappings":";AAoBO,SAASA,EAAWC,GAAeC,GAAuB;AAC/D,EAAAC;AAAA,IACE,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAOF,CAAI,KAAK,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAOC,CAAI;AAAA,IACvF;AAAA,IACA;AAAA,MACE,MAAM,EAAE,MAAAD,GAAM,MAAAC,EAAA;AAAA,MACd,MAAM;AAAA,IAAA;AAAA,EACR;AAGF,QAAME,IAAI,OAAOH,CAAI,EAAE,YAAA,GACjBI,IAAI,OAAOH,CAAI,EAAE,YAAA;AAEvB,MAAIE,MAAMC,EAAG,QAAO;AACpB,MAAI,CAACD,EAAE,UAAU,CAACC,EAAE,OAAQ,QAAO;AAEnC,QAAMC,IAAUF,EAAE,QACZG,IAAUF,EAAE,QAGZG,IAAqB,MAAM,KAAK,EAAE,QAAQF,IAAU,EAAA,GAAK,CAACG,GAAGC,MAAM,CAACA,CAAC,CAAC;AAC5E,WAASC,IAAI,GAAGA,KAAKJ,GAASI;AAC5B,IAAAH,EAAO,CAAC,EAAEG,CAAC,IAAIA;AAIjB,WAASD,IAAI,GAAGA,KAAKJ,GAASI;AAC5B,aAASC,IAAI,GAAGA,KAAKJ,GAASI,KAAK;AACjC,YAAMC,IAAOR,EAAEM,IAAI,CAAC,MAAML,EAAEM,IAAI,CAAC,IAAI,IAAI;AACzC,MAAAH,EAAOE,CAAC,EAAEC,CAAC,IAAI,KAAK;AAAA,QAClBH,EAAOE,IAAI,CAAC,EAAEC,CAAC,IAAI;AAAA;AAAA,QACnBH,EAAOE,CAAC,EAAEC,IAAI,CAAC,IAAI;AAAA;AAAA,QACnBH,EAAOE,IAAI,CAAC,EAAEC,IAAI,CAAC,IAAIC;AAAA;AAAA,MAAA;AAAA,IAE3B;AAKF,SAAO,IAFUJ,EAAOF,CAAO,EAAEC,CAAO,IAElB,KAAK,IAAID,GAASC,CAAO;AACjD;"}
1
+ {"version":3,"file":"similarity.js","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (a.length === 0) return b.length === 0 ? 1 : 0;\n if (b.length === 0) return 0;\n\n // Swap to ensure we use the smaller string for columns (O(min(A,B)) space)\n const [shorter, longer] = a.length < b.length ? [a, b] : [b, a];\n const shorterLength = shorter.length;\n const longerLength = longer.length;\n\n let prevRow = Array.from({ length: shorterLength + 1 }, (_, i) => i);\n let currRow = new Array(shorterLength + 1);\n\n for (let i = 1; i <= longerLength; i++) {\n currRow[0] = i;\n for (let j = 1; j <= shorterLength; j++) {\n const cost = longer[i - 1] === shorter[j - 1] ? 0 : 1;\n currRow[j] = Math.min(\n currRow[j - 1] + 1, // insertion\n prevRow[j] + 1, // deletion\n prevRow[j - 1] + cost, // substitution\n );\n }\n // Swap rows for the next iteration (avoid allocation)\n [prevRow, currRow] = [currRow, prevRow];\n }\n\n // After the loop, a result is in prevRow because of the swap\n const distance = prevRow[shorterLength];\n\n return 1 - distance / Math.max(a.length, b.length);\n}\n"],"names":["similarity","str1","str2","assert","a","b","shorter","longer","shorterLength","longerLength","prevRow","_","i","currRow","j","cost"],"mappings":";AAoBO,SAASA,EAAWC,GAAeC,GAAuB;AAC/D,EAAAC;AAAA,IACE,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAOF,CAAI,KAAK,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAOC,CAAI;AAAA,IACvF;AAAA,IACA;AAAA,MACE,MAAM,EAAE,MAAAD,GAAM,MAAAC,EAAA;AAAA,MACd,MAAM;AAAA,IAAA;AAAA,EACR;AAGF,QAAME,IAAI,OAAOH,CAAI,EAAE,YAAA,GACjBI,IAAI,OAAOH,CAAI,EAAE,YAAA;AAEvB,MAAIE,MAAMC,EAAG,QAAO;AACpB,MAAID,EAAE,WAAW,UAAUC,EAAE,WAAW,IAAI,IAAI;AAChD,MAAIA,EAAE,WAAW,EAAG,QAAO;AAG3B,QAAM,CAACC,GAASC,CAAM,IAAIH,EAAE,SAASC,EAAE,SAAS,CAACD,GAAGC,CAAC,IAAI,CAACA,GAAGD,CAAC,GACxDI,IAAgBF,EAAQ,QACxBG,IAAeF,EAAO;AAE5B,MAAIG,IAAU,MAAM,KAAK,EAAE,QAAQF,IAAgB,KAAK,CAACG,GAAGC,MAAMA,CAAC,GAC/DC,IAAU,IAAI,MAAML,IAAgB,CAAC;AAEzC,WAASI,IAAI,GAAGA,KAAKH,GAAcG,KAAK;AACtC,IAAAC,EAAQ,CAAC,IAAID;AACb,aAASE,IAAI,GAAGA,KAAKN,GAAeM,KAAK;AACvC,YAAMC,IAAOR,EAAOK,IAAI,CAAC,MAAMN,EAAQQ,IAAI,CAAC,IAAI,IAAI;AACpD,MAAAD,EAAQC,CAAC,IAAI,KAAK;AAAA,QAChBD,EAAQC,IAAI,CAAC,IAAI;AAAA;AAAA,QACjBJ,EAAQI,CAAC,IAAI;AAAA;AAAA,QACbJ,EAAQI,IAAI,CAAC,IAAIC;AAAA;AAAA,MAAA;AAAA,IAErB;AAEA,KAACL,GAASG,CAAO,IAAI,CAACA,GAASH,CAAO;AAAA,EACxC;AAKA,SAAO,IAFUA,EAAQF,CAAa,IAEhB,KAAK,IAAIJ,EAAE,QAAQC,EAAE,MAAM;AACnD;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(e,t=25,r=!1,u="…"){if(e.length<=t)return e;const n=r?e.substring(0,t).lastIndexOf(" "):t,c=n>0?n:t;return`${e.substring(0,c).trim()}${u}`}exports.truncate=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../function/assert.cjs");function o(t,e=25,s=!1,u="…"){if(n.assert(typeof t=="string","First argument must be a string",{args:{str:t},type:TypeError}),n.assert(typeof e=="number"&&e>=0&&Number.isFinite(e),"Limit must be a non-negative finite number",{args:{limit:e},type:TypeError}),t.length<=e)return t;const r=s?t.substring(0,e).lastIndexOf(" "):e,a=r>0?r:e;return`${t.substring(0,a).trim()}${u}`}exports.truncate=o;
2
2
  //# sourceMappingURL=truncate.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"truncate.cjs","sources":["../../src/string/truncate.ts"],"sourcesContent":["/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n if (str.length <= limit) return str;\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","_limit","effectiveLimit"],"mappings":"gFAkBO,SAASA,EAASC,EAAaC,EAAQ,GAAIC,EAAgB,GAAOC,EAAW,IAAa,CAC/F,GAAIH,EAAI,QAAUC,EAAO,OAAOD,EAEhC,MAAMI,EAASF,EAAgBF,EAAI,UAAU,EAAGC,CAAK,EAAE,YAAY,GAAG,EAAIA,EACpEI,EAAiBD,EAAS,EAAIA,EAASH,EAE7C,MAAO,GAAGD,EAAI,UAAU,EAAGK,CAAc,EAAE,KAAA,CAAM,GAAGF,CAAQ,EAC9D"}
1
+ {"version":3,"file":"truncate.cjs","sources":["../../src/string/truncate.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n *\n * @throws {TypeError} If str is not a string or limit is not a positive number.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n assert(typeof str === 'string', 'First argument must be a string', {\n args: { str },\n type: TypeError,\n });\n assert(\n typeof limit === 'number' && limit >= 0 && Number.isFinite(limit),\n 'Limit must be a non-negative finite number',\n { args: { limit }, type: TypeError },\n );\n\n if (str.length <= limit) {\n return str;\n }\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","assert","_limit","effectiveLimit"],"mappings":"0HAsBO,SAASA,EAASC,EAAaC,EAAQ,GAAIC,EAAgB,GAAOC,EAAW,IAAa,CAW/F,GAVAC,EAAAA,OAAO,OAAOJ,GAAQ,SAAU,kCAAmC,CACjE,KAAM,CAAE,IAAAA,CAAA,EACR,KAAM,SAAA,CACP,EACDI,EAAAA,OACE,OAAOH,GAAU,UAAYA,GAAS,GAAK,OAAO,SAASA,CAAK,EAChE,6CACA,CAAE,KAAM,CAAE,MAAAA,CAAA,EAAS,KAAM,SAAA,CAAU,EAGjCD,EAAI,QAAUC,EAChB,OAAOD,EAGT,MAAMK,EAASH,EAAgBF,EAAI,UAAU,EAAGC,CAAK,EAAE,YAAY,GAAG,EAAIA,EACpEK,EAAiBD,EAAS,EAAIA,EAASJ,EAE7C,MAAO,GAAGD,EAAI,UAAU,EAAGM,CAAc,EAAE,KAAA,CAAM,GAAGH,CAAQ,EAC9D"}
@@ -1,9 +1,18 @@
1
- function c(n, e = 25, f = !1, r = "") {
2
- if (n.length <= e) return n;
3
- const t = f ? n.substring(0, e).lastIndexOf(" ") : e, u = t > 0 ? t : e;
4
- return `${n.substring(0, u).trim()}${r}`;
1
+ import { assert as t } from "../function/assert.js";
2
+ function f(r, e = 25, s = !1, u = "…") {
3
+ if (t(typeof r == "string", "First argument must be a string", {
4
+ args: { str: r },
5
+ type: TypeError
6
+ }), t(
7
+ typeof e == "number" && e >= 0 && Number.isFinite(e),
8
+ "Limit must be a non-negative finite number",
9
+ { args: { limit: e }, type: TypeError }
10
+ ), r.length <= e)
11
+ return r;
12
+ const n = s ? r.substring(0, e).lastIndexOf(" ") : e, o = n > 0 ? n : e;
13
+ return `${r.substring(0, o).trim()}${u}`;
5
14
  }
6
15
  export {
7
- c as truncate
16
+ f as truncate
8
17
  };
9
18
  //# sourceMappingURL=truncate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"truncate.js","sources":["../../src/string/truncate.ts"],"sourcesContent":["/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n if (str.length <= limit) return str;\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","_limit","effectiveLimit"],"mappings":"AAkBO,SAASA,EAASC,GAAaC,IAAQ,IAAIC,IAAgB,IAAOC,IAAW,KAAa;AAC/F,MAAIH,EAAI,UAAUC,EAAO,QAAOD;AAEhC,QAAMI,IAASF,IAAgBF,EAAI,UAAU,GAAGC,CAAK,EAAE,YAAY,GAAG,IAAIA,GACpEI,IAAiBD,IAAS,IAAIA,IAASH;AAE7C,SAAO,GAAGD,EAAI,UAAU,GAAGK,CAAc,EAAE,KAAA,CAAM,GAAGF,CAAQ;AAC9D;"}
1
+ {"version":3,"file":"truncate.js","sources":["../../src/string/truncate.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n *\n * @throws {TypeError} If str is not a string or limit is not a positive number.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n assert(typeof str === 'string', 'First argument must be a string', {\n args: { str },\n type: TypeError,\n });\n assert(\n typeof limit === 'number' && limit >= 0 && Number.isFinite(limit),\n 'Limit must be a non-negative finite number',\n { args: { limit }, type: TypeError },\n );\n\n if (str.length <= limit) {\n return str;\n }\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","assert","_limit","effectiveLimit"],"mappings":";AAsBO,SAASA,EAASC,GAAaC,IAAQ,IAAIC,IAAgB,IAAOC,IAAW,KAAa;AAW/F,MAVAC,EAAO,OAAOJ,KAAQ,UAAU,mCAAmC;AAAA,IACjE,MAAM,EAAE,KAAAA,EAAA;AAAA,IACR,MAAM;AAAA,EAAA,CACP,GACDI;AAAA,IACE,OAAOH,KAAU,YAAYA,KAAS,KAAK,OAAO,SAASA,CAAK;AAAA,IAChE;AAAA,IACA,EAAE,MAAM,EAAE,OAAAA,EAAA,GAAS,MAAM,UAAA;AAAA,EAAU,GAGjCD,EAAI,UAAUC;AAChB,WAAOD;AAGT,QAAMK,IAASH,IAAgBF,EAAI,UAAU,GAAGC,CAAK,EAAE,YAAY,GAAG,IAAIA,GACpEK,IAAiBD,IAAS,IAAIA,IAASJ;AAE7C,SAAO,GAAGD,EAAI,UAAU,GAAGM,CAAc,EAAE,KAAA,CAAM,GAAGH,CAAQ;AAC9D;"}
package/dist/typed/is.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./ge.cjs"),n=require("./gt.cjs"),o=require("./isDefined.cjs"),c=require("./isEmpty.cjs"),r=require("./isEqual.cjs"),u=require("./isEven.cjs"),q=require("./isMatch.cjs"),l=require("./isNegative.cjs"),d=require("./isNil.cjs"),g=require("./isOdd.cjs"),a=require("./isPositive.cjs"),v=require("./isRegex.cjs"),p=require("./isWithin.cjs"),f=require("./isZero.cjs"),m=require("./le.cjs"),E=require("./lt.cjs"),h=require("./typeOf.cjs");function y(i,s){if(!i)throw new Error("Type must be provided");return{defined:o.isDefined,empty:c.isEmpty,eq:e=>r.isEqual(...e),even:u.isEven,ge:e=>t.ge(...e),gt:e=>n.gt(...e),le:e=>m.le(...e),lt:e=>E.lt(...e),match:e=>q.isMatch(...e),ne:e=>!r.isEqual(...e),negative:l.isNegative,nil:d.isNil,odd:g.isOdd,positive:a.isPositive,regex:v.isRegex,within:e=>p.isWithin(...e),zero:f.isZero}[i]?.(s)??h.typeOf(s)===i}exports.is=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../function/assert.cjs"),n=require("./ge.cjs"),o=require("./gt.cjs"),c=require("./isDefined.cjs"),u=require("./isEmpty.cjs"),r=require("./isEqual.cjs"),q=require("./isEven.cjs"),a=require("./isMatch.cjs"),l=require("./isNegative.cjs"),d=require("./isNil.cjs"),g=require("./isOdd.cjs"),v=require("./isPositive.cjs"),p=require("./isRegex.cjs"),m=require("./isWithin.cjs"),E=require("./isZero.cjs"),f=require("./le.cjs"),h=require("./lt.cjs"),y=require("./typeOf.cjs");function O(i,s){return t.assert(!!i,"Type must be provided",{args:{type:i},type:Error}),{defined:c.isDefined,empty:u.isEmpty,eq:e=>r.isEqual(...e),even:q.isEven,ge:e=>n.ge(...e),gt:e=>o.gt(...e),le:e=>f.le(...e),lt:e=>h.lt(...e),match:e=>a.isMatch(...e),ne:e=>!r.isEqual(...e),negative:l.isNegative,nil:d.isNil,odd:g.isOdd,positive:v.isPositive,regex:p.isRegex,within:e=>m.isWithin(...e),zero:E.isZero}[i]?.(s)??y.typeOf(s)===i}exports.is=O;
2
2
  //# sourceMappingURL=is.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is.cjs","sources":["../../src/typed/is.ts"],"sourcesContent":["import { ge } from './ge';\nimport { gt } from './gt';\nimport { isDefined } from './isDefined';\nimport { isEmpty } from './isEmpty';\nimport { isEqual } from './isEqual';\nimport { isEven } from './isEven';\nimport { isMatch } from './isMatch';\nimport { isNegative } from './isNegative';\nimport { isNil } from './isNil';\nimport { isOdd } from './isOdd';\nimport { isPositive } from './isPositive';\nimport { isRegex } from './isRegex';\nimport { isWithin } from './isWithin';\nimport { isZero } from './isZero';\nimport { le } from './le';\nimport { lt } from './lt';\nimport { type ArgType, typeOf } from './typeOf';\n\ntype isType =\n | ArgType\n | 'defined'\n | 'empty'\n | 'eq'\n | 'even'\n | 'ge'\n | 'gt'\n | 'le'\n | 'lt'\n | 'match'\n | 'ne'\n | 'negative'\n | 'nil'\n | 'odd'\n | 'positive'\n | 'regex'\n | 'within'\n | 'zero';\n\n/**\n * @description\n * Checks if the value type of argument.\n *\n * @example\n * ```ts\n * is('array', []);\n * is('boolean', true);\n * is('date', new Date());\n * is('defined', 123);\n * is('empty', []);\n * is('even', 2);\n * is('function', () => {});\n * is('match', { a: 1, b: 2 }, { a: 1 });\n * is('nan', Number.NaN);\n * is('negative', -123);\n * is('nil', null);\n * is('null', null);\n * is('number', 123);\n * is('object', {});\n * is('odd', 3);\n * is('positive', 123);\n * is('string', 'hello');\n * is('symbol', Symbol('test'));\n * is('regex', /abc/);\n * is('string', 'hello world');\n * is('undefined', undefined);\n * is('within', 1, 2, 3);\n * is('zero', 0);\n * is('eq', [1, 2, 3], [1, 2, 3]);\n * is('ne', [1, 2, 3], [1, 2]);\n * is('ge', 5, 5);\n * is('gt', 5, 3);\n * is('le', 5, 5);\n * is('lt', 3, 5);\n * ```\n *\n * @param type - The type to check against.\n * @param args - The argument to be checked.\n *\n * @returns `true` if the value is of the specified type, else `false`.\n */\nexport function is(type: 'within', ...args: Parameters<typeof isWithin>): boolean;\nexport function is(type: 'eq', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'ne', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'gt', ...args: Parameters<typeof gt>): boolean;\nexport function is(type: 'ge', ...args: Parameters<typeof ge>): boolean;\nexport function is(type: 'lt', ...args: Parameters<typeof lt>): boolean;\nexport function is(type: 'le', ...args: Parameters<typeof le>): boolean;\nexport function is(type: 'match', ...args: Parameters<typeof isMatch>): boolean;\nexport function is(type: 'empty', ...args: Parameters<typeof isEmpty>): boolean;\nexport function is(type: 'array', arg: unknown): arg is Array<unknown>;\nexport function is(type: 'string', arg: unknown): arg is string;\nexport function is(type: 'number', arg: unknown): arg is number;\nexport function is(type: 'object', arg: unknown): arg is object;\nexport function is(type: 'nil', arg: unknown): arg is null | undefined;\nexport function is(type: 'primitive', arg: unknown): arg is string | number | boolean;\nexport function is(type: isType, arg: unknown): boolean;\nexport function is(type: string, arg: unknown): boolean {\n if (!type) {\n throw new Error('Type must be provided');\n }\n\n const compare = {\n defined: isDefined,\n empty: isEmpty,\n eq: (args: Parameters<typeof isEqual>) => isEqual(...args),\n even: isEven,\n ge: (args: Parameters<typeof ge>) => ge(...args),\n gt: (args: Parameters<typeof gt>) => gt(...args),\n le: (args: Parameters<typeof le>) => le(...args),\n lt: (args: Parameters<typeof lt>) => lt(...args),\n match: (args: Parameters<typeof isMatch>) => isMatch(...args),\n ne: (args: Parameters<typeof isEqual>) => !isEqual(...args),\n negative: isNegative,\n nil: isNil,\n odd: isOdd,\n positive: isPositive,\n regex: isRegex,\n within: (args: Parameters<typeof isWithin>) => isWithin(...args),\n zero: isZero,\n };\n\n return compare[type as keyof typeof compare]?.(arg) ?? typeOf(arg) === type;\n}\n"],"names":["is","type","arg","isDefined","isEmpty","args","isEqual","isEven","ge","gt","le","lt","isMatch","isNegative","isNil","isOdd","isPositive","isRegex","isWithin","isZero","typeOf"],"mappings":"+gBAgGO,SAASA,EAAGC,EAAcC,EAAuB,CACtD,GAAI,CAACD,EACH,MAAM,IAAI,MAAM,uBAAuB,EAuBzC,MApBgB,CACd,QAASE,EAAAA,UACT,MAAOC,EAAAA,QACP,GAAKC,GAAqCC,EAAAA,QAAQ,GAAGD,CAAI,EACzD,KAAME,EAAAA,OACN,GAAKF,GAAgCG,EAAAA,GAAG,GAAGH,CAAI,EAC/C,GAAKA,GAAgCI,EAAAA,GAAG,GAAGJ,CAAI,EAC/C,GAAKA,GAAgCK,EAAAA,GAAG,GAAGL,CAAI,EAC/C,GAAKA,GAAgCM,EAAAA,GAAG,GAAGN,CAAI,EAC/C,MAAQA,GAAqCO,EAAAA,QAAQ,GAAGP,CAAI,EAC5D,GAAKA,GAAqC,CAACC,EAAAA,QAAQ,GAAGD,CAAI,EAC1D,SAAUQ,EAAAA,WACV,IAAKC,EAAAA,MACL,IAAKC,EAAAA,MACL,SAAUC,EAAAA,WACV,MAAOC,EAAAA,QACP,OAASZ,GAAsCa,EAAAA,SAAS,GAAGb,CAAI,EAC/D,KAAMc,EAAAA,MAAA,EAGOlB,CAA4B,IAAIC,CAAG,GAAKkB,EAAAA,OAAOlB,CAAG,IAAMD,CACzE"}
1
+ {"version":3,"file":"is.cjs","sources":["../../src/typed/is.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { ge } from './ge';\nimport { gt } from './gt';\nimport { isDefined } from './isDefined';\nimport { isEmpty } from './isEmpty';\nimport { isEqual } from './isEqual';\nimport { isEven } from './isEven';\nimport { isMatch } from './isMatch';\nimport { isNegative } from './isNegative';\nimport { isNil } from './isNil';\nimport { isOdd } from './isOdd';\nimport { isPositive } from './isPositive';\nimport { isRegex } from './isRegex';\nimport { isWithin } from './isWithin';\nimport { isZero } from './isZero';\nimport { le } from './le';\nimport { lt } from './lt';\nimport { type ArgType, typeOf } from './typeOf';\n\ntype isType =\n | ArgType\n | 'defined'\n | 'empty'\n | 'eq'\n | 'even'\n | 'ge'\n | 'gt'\n | 'le'\n | 'lt'\n | 'match'\n | 'ne'\n | 'negative'\n | 'nil'\n | 'odd'\n | 'positive'\n | 'regex'\n | 'within'\n | 'zero';\n\n/**\n * @description\n * Checks if the value type of argument.\n *\n * @example\n * ```ts\n * is('array', []);\n * is('boolean', true);\n * is('date', new Date());\n * is('defined', 123);\n * is('empty', []);\n * is('even', 2);\n * is('function', () => {});\n * is('match', { a: 1, b: 2 }, { a: 1 });\n * is('nan', Number.NaN);\n * is('negative', -123);\n * is('nil', null);\n * is('null', null);\n * is('number', 123);\n * is('object', {});\n * is('odd', 3);\n * is('positive', 123);\n * is('string', 'hello');\n * is('symbol', Symbol('test'));\n * is('regex', /abc/);\n * is('string', 'hello world');\n * is('undefined', undefined);\n * is('within', 1, 2, 3);\n * is('zero', 0);\n * is('eq', [1, 2, 3], [1, 2, 3]);\n * is('ne', [1, 2, 3], [1, 2]);\n * is('ge', 5, 5);\n * is('gt', 5, 3);\n * is('le', 5, 5);\n * is('lt', 3, 5);\n * ```\n *\n * @param type - The type to check against.\n * @param args - The argument to be checked.\n *\n * @returns `true` if the value is of the specified type, else `false`.\n */\nexport function is(type: 'within', ...args: Parameters<typeof isWithin>): boolean;\nexport function is(type: 'eq', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'ne', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'gt', ...args: Parameters<typeof gt>): boolean;\nexport function is(type: 'ge', ...args: Parameters<typeof ge>): boolean;\nexport function is(type: 'lt', ...args: Parameters<typeof lt>): boolean;\nexport function is(type: 'le', ...args: Parameters<typeof le>): boolean;\nexport function is(type: 'match', ...args: Parameters<typeof isMatch>): boolean;\nexport function is(type: 'empty', ...args: Parameters<typeof isEmpty>): boolean;\nexport function is(type: 'array', arg: unknown): arg is Array<unknown>;\nexport function is(type: 'string', arg: unknown): arg is string;\nexport function is(type: 'number', arg: unknown): arg is number;\nexport function is(type: 'object', arg: unknown): arg is object;\nexport function is(type: 'nil', arg: unknown): arg is null | undefined;\nexport function is(type: 'primitive', arg: unknown): arg is string | number | boolean;\nexport function is(type: isType, arg: unknown): boolean;\nexport function is(type: string, arg: unknown): boolean {\n assert(Boolean(type), 'Type must be provided', { args: { type }, type: Error });\n\n const compare = {\n defined: isDefined,\n empty: isEmpty,\n eq: (args: Parameters<typeof isEqual>) => isEqual(...args),\n even: isEven,\n ge: (args: Parameters<typeof ge>) => ge(...args),\n gt: (args: Parameters<typeof gt>) => gt(...args),\n le: (args: Parameters<typeof le>) => le(...args),\n lt: (args: Parameters<typeof lt>) => lt(...args),\n match: (args: Parameters<typeof isMatch>) => isMatch(...args),\n ne: (args: Parameters<typeof isEqual>) => !isEqual(...args),\n negative: isNegative,\n nil: isNil,\n odd: isOdd,\n positive: isPositive,\n regex: isRegex,\n within: (args: Parameters<typeof isWithin>) => isWithin(...args),\n zero: isZero,\n };\n\n return compare[type as keyof typeof compare]?.(arg) ?? typeOf(arg) === type;\n}\n"],"names":["is","type","arg","assert","isDefined","isEmpty","args","isEqual","isEven","ge","gt","le","lt","isMatch","isNegative","isNil","isOdd","isPositive","isRegex","isWithin","isZero","typeOf"],"mappings":"mjBAiGO,SAASA,EAAGC,EAAcC,EAAuB,CACtDC,OAAAA,EAAAA,OAAO,EAAQF,EAAO,wBAAyB,CAAE,KAAM,CAAE,KAAAA,CAAA,EAAQ,KAAM,MAAO,EAE9D,CACd,QAASG,EAAAA,UACT,MAAOC,EAAAA,QACP,GAAKC,GAAqCC,EAAAA,QAAQ,GAAGD,CAAI,EACzD,KAAME,EAAAA,OACN,GAAKF,GAAgCG,EAAAA,GAAG,GAAGH,CAAI,EAC/C,GAAKA,GAAgCI,EAAAA,GAAG,GAAGJ,CAAI,EAC/C,GAAKA,GAAgCK,EAAAA,GAAG,GAAGL,CAAI,EAC/C,GAAKA,GAAgCM,EAAAA,GAAG,GAAGN,CAAI,EAC/C,MAAQA,GAAqCO,EAAAA,QAAQ,GAAGP,CAAI,EAC5D,GAAKA,GAAqC,CAACC,EAAAA,QAAQ,GAAGD,CAAI,EAC1D,SAAUQ,EAAAA,WACV,IAAKC,EAAAA,MACL,IAAKC,EAAAA,MACL,SAAUC,EAAAA,WACV,MAAOC,EAAAA,QACP,OAASZ,GAAsCa,EAAAA,SAAS,GAAGb,CAAI,EAC/D,KAAMc,EAAAA,MAAA,EAGOnB,CAA4B,IAAIC,CAAG,GAAKmB,EAAAA,OAAOnB,CAAG,IAAMD,CACzE"}
package/dist/typed/is.js CHANGED
@@ -1,44 +1,43 @@
1
- import { ge as t } from "./ge.js";
2
- import { gt as e } from "./gt.js";
3
- import { isDefined as p } from "./isDefined.js";
4
- import { isEmpty as f } from "./isEmpty.js";
1
+ import { assert as t } from "../function/assert.js";
2
+ import { ge as e } from "./ge.js";
3
+ import { gt as p } from "./gt.js";
4
+ import { isDefined as f } from "./isDefined.js";
5
+ import { isEmpty as s } from "./isEmpty.js";
5
6
  import { isEqual as m } from "./isEqual.js";
6
- import { isEven as s } from "./isEven.js";
7
- import { isMatch as n } from "./isMatch.js";
7
+ import { isEven as n } from "./isEven.js";
8
+ import { isMatch as a } from "./isMatch.js";
8
9
  import { isNegative as d } from "./isNegative.js";
9
10
  import { isNil as g } from "./isNil.js";
10
11
  import { isOdd as l } from "./isOdd.js";
11
12
  import { isPositive as v } from "./isPositive.js";
12
- import { isRegex as a } from "./isRegex.js";
13
- import { isWithin as c } from "./isWithin.js";
14
- import { isZero as h } from "./isZero.js";
15
- import { le as u } from "./le.js";
16
- import { lt as E } from "./lt.js";
17
- import { typeOf as w } from "./typeOf.js";
18
- function C(o, r) {
19
- if (!o)
20
- throw new Error("Type must be provided");
21
- return {
22
- defined: p,
23
- empty: f,
24
- eq: (i) => m(...i),
25
- even: s,
26
- ge: (i) => t(...i),
27
- gt: (i) => e(...i),
28
- le: (i) => u(...i),
29
- lt: (i) => E(...i),
30
- match: (i) => n(...i),
31
- ne: (i) => !m(...i),
13
+ import { isRegex as c } from "./isRegex.js";
14
+ import { isWithin as h } from "./isWithin.js";
15
+ import { isZero as u } from "./isZero.js";
16
+ import { le as E } from "./le.js";
17
+ import { lt as x } from "./lt.js";
18
+ import { typeOf as q } from "./typeOf.js";
19
+ function G(r, i) {
20
+ return t(!!r, "Type must be provided", { args: { type: r }, type: Error }), {
21
+ defined: f,
22
+ empty: s,
23
+ eq: (o) => m(...o),
24
+ even: n,
25
+ ge: (o) => e(...o),
26
+ gt: (o) => p(...o),
27
+ le: (o) => E(...o),
28
+ lt: (o) => x(...o),
29
+ match: (o) => a(...o),
30
+ ne: (o) => !m(...o),
32
31
  negative: d,
33
32
  nil: g,
34
33
  odd: l,
35
34
  positive: v,
36
- regex: a,
37
- within: (i) => c(...i),
38
- zero: h
39
- }[o]?.(r) ?? w(r) === o;
35
+ regex: c,
36
+ within: (o) => h(...o),
37
+ zero: u
38
+ }[r]?.(i) ?? q(i) === r;
40
39
  }
41
40
  export {
42
- C as is
41
+ G as is
43
42
  };
44
43
  //# sourceMappingURL=is.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is.js","sources":["../../src/typed/is.ts"],"sourcesContent":["import { ge } from './ge';\nimport { gt } from './gt';\nimport { isDefined } from './isDefined';\nimport { isEmpty } from './isEmpty';\nimport { isEqual } from './isEqual';\nimport { isEven } from './isEven';\nimport { isMatch } from './isMatch';\nimport { isNegative } from './isNegative';\nimport { isNil } from './isNil';\nimport { isOdd } from './isOdd';\nimport { isPositive } from './isPositive';\nimport { isRegex } from './isRegex';\nimport { isWithin } from './isWithin';\nimport { isZero } from './isZero';\nimport { le } from './le';\nimport { lt } from './lt';\nimport { type ArgType, typeOf } from './typeOf';\n\ntype isType =\n | ArgType\n | 'defined'\n | 'empty'\n | 'eq'\n | 'even'\n | 'ge'\n | 'gt'\n | 'le'\n | 'lt'\n | 'match'\n | 'ne'\n | 'negative'\n | 'nil'\n | 'odd'\n | 'positive'\n | 'regex'\n | 'within'\n | 'zero';\n\n/**\n * @description\n * Checks if the value type of argument.\n *\n * @example\n * ```ts\n * is('array', []);\n * is('boolean', true);\n * is('date', new Date());\n * is('defined', 123);\n * is('empty', []);\n * is('even', 2);\n * is('function', () => {});\n * is('match', { a: 1, b: 2 }, { a: 1 });\n * is('nan', Number.NaN);\n * is('negative', -123);\n * is('nil', null);\n * is('null', null);\n * is('number', 123);\n * is('object', {});\n * is('odd', 3);\n * is('positive', 123);\n * is('string', 'hello');\n * is('symbol', Symbol('test'));\n * is('regex', /abc/);\n * is('string', 'hello world');\n * is('undefined', undefined);\n * is('within', 1, 2, 3);\n * is('zero', 0);\n * is('eq', [1, 2, 3], [1, 2, 3]);\n * is('ne', [1, 2, 3], [1, 2]);\n * is('ge', 5, 5);\n * is('gt', 5, 3);\n * is('le', 5, 5);\n * is('lt', 3, 5);\n * ```\n *\n * @param type - The type to check against.\n * @param args - The argument to be checked.\n *\n * @returns `true` if the value is of the specified type, else `false`.\n */\nexport function is(type: 'within', ...args: Parameters<typeof isWithin>): boolean;\nexport function is(type: 'eq', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'ne', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'gt', ...args: Parameters<typeof gt>): boolean;\nexport function is(type: 'ge', ...args: Parameters<typeof ge>): boolean;\nexport function is(type: 'lt', ...args: Parameters<typeof lt>): boolean;\nexport function is(type: 'le', ...args: Parameters<typeof le>): boolean;\nexport function is(type: 'match', ...args: Parameters<typeof isMatch>): boolean;\nexport function is(type: 'empty', ...args: Parameters<typeof isEmpty>): boolean;\nexport function is(type: 'array', arg: unknown): arg is Array<unknown>;\nexport function is(type: 'string', arg: unknown): arg is string;\nexport function is(type: 'number', arg: unknown): arg is number;\nexport function is(type: 'object', arg: unknown): arg is object;\nexport function is(type: 'nil', arg: unknown): arg is null | undefined;\nexport function is(type: 'primitive', arg: unknown): arg is string | number | boolean;\nexport function is(type: isType, arg: unknown): boolean;\nexport function is(type: string, arg: unknown): boolean {\n if (!type) {\n throw new Error('Type must be provided');\n }\n\n const compare = {\n defined: isDefined,\n empty: isEmpty,\n eq: (args: Parameters<typeof isEqual>) => isEqual(...args),\n even: isEven,\n ge: (args: Parameters<typeof ge>) => ge(...args),\n gt: (args: Parameters<typeof gt>) => gt(...args),\n le: (args: Parameters<typeof le>) => le(...args),\n lt: (args: Parameters<typeof lt>) => lt(...args),\n match: (args: Parameters<typeof isMatch>) => isMatch(...args),\n ne: (args: Parameters<typeof isEqual>) => !isEqual(...args),\n negative: isNegative,\n nil: isNil,\n odd: isOdd,\n positive: isPositive,\n regex: isRegex,\n within: (args: Parameters<typeof isWithin>) => isWithin(...args),\n zero: isZero,\n };\n\n return compare[type as keyof typeof compare]?.(arg) ?? typeOf(arg) === type;\n}\n"],"names":["is","type","arg","isDefined","isEmpty","args","isEqual","isEven","ge","gt","le","lt","isMatch","isNegative","isNil","isOdd","isPositive","isRegex","isWithin","isZero","typeOf"],"mappings":";;;;;;;;;;;;;;;;;AAgGO,SAASA,EAAGC,GAAcC,GAAuB;AACtD,MAAI,CAACD;AACH,UAAM,IAAI,MAAM,uBAAuB;AAuBzC,SApBgB;AAAA,IACd,SAASE;AAAA,IACT,OAAOC;AAAA,IACP,IAAI,CAACC,MAAqCC,EAAQ,GAAGD,CAAI;AAAA,IACzD,MAAME;AAAA,IACN,IAAI,CAACF,MAAgCG,EAAG,GAAGH,CAAI;AAAA,IAC/C,IAAI,CAACA,MAAgCI,EAAG,GAAGJ,CAAI;AAAA,IAC/C,IAAI,CAACA,MAAgCK,EAAG,GAAGL,CAAI;AAAA,IAC/C,IAAI,CAACA,MAAgCM,EAAG,GAAGN,CAAI;AAAA,IAC/C,OAAO,CAACA,MAAqCO,EAAQ,GAAGP,CAAI;AAAA,IAC5D,IAAI,CAACA,MAAqC,CAACC,EAAQ,GAAGD,CAAI;AAAA,IAC1D,UAAUQ;AAAA,IACV,KAAKC;AAAA,IACL,KAAKC;AAAA,IACL,UAAUC;AAAA,IACV,OAAOC;AAAA,IACP,QAAQ,CAACZ,MAAsCa,EAAS,GAAGb,CAAI;AAAA,IAC/D,MAAMc;AAAA,EAAA,EAGOlB,CAA4B,IAAIC,CAAG,KAAKkB,EAAOlB,CAAG,MAAMD;AACzE;"}
1
+ {"version":3,"file":"is.js","sources":["../../src/typed/is.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { ge } from './ge';\nimport { gt } from './gt';\nimport { isDefined } from './isDefined';\nimport { isEmpty } from './isEmpty';\nimport { isEqual } from './isEqual';\nimport { isEven } from './isEven';\nimport { isMatch } from './isMatch';\nimport { isNegative } from './isNegative';\nimport { isNil } from './isNil';\nimport { isOdd } from './isOdd';\nimport { isPositive } from './isPositive';\nimport { isRegex } from './isRegex';\nimport { isWithin } from './isWithin';\nimport { isZero } from './isZero';\nimport { le } from './le';\nimport { lt } from './lt';\nimport { type ArgType, typeOf } from './typeOf';\n\ntype isType =\n | ArgType\n | 'defined'\n | 'empty'\n | 'eq'\n | 'even'\n | 'ge'\n | 'gt'\n | 'le'\n | 'lt'\n | 'match'\n | 'ne'\n | 'negative'\n | 'nil'\n | 'odd'\n | 'positive'\n | 'regex'\n | 'within'\n | 'zero';\n\n/**\n * @description\n * Checks if the value type of argument.\n *\n * @example\n * ```ts\n * is('array', []);\n * is('boolean', true);\n * is('date', new Date());\n * is('defined', 123);\n * is('empty', []);\n * is('even', 2);\n * is('function', () => {});\n * is('match', { a: 1, b: 2 }, { a: 1 });\n * is('nan', Number.NaN);\n * is('negative', -123);\n * is('nil', null);\n * is('null', null);\n * is('number', 123);\n * is('object', {});\n * is('odd', 3);\n * is('positive', 123);\n * is('string', 'hello');\n * is('symbol', Symbol('test'));\n * is('regex', /abc/);\n * is('string', 'hello world');\n * is('undefined', undefined);\n * is('within', 1, 2, 3);\n * is('zero', 0);\n * is('eq', [1, 2, 3], [1, 2, 3]);\n * is('ne', [1, 2, 3], [1, 2]);\n * is('ge', 5, 5);\n * is('gt', 5, 3);\n * is('le', 5, 5);\n * is('lt', 3, 5);\n * ```\n *\n * @param type - The type to check against.\n * @param args - The argument to be checked.\n *\n * @returns `true` if the value is of the specified type, else `false`.\n */\nexport function is(type: 'within', ...args: Parameters<typeof isWithin>): boolean;\nexport function is(type: 'eq', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'ne', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'gt', ...args: Parameters<typeof gt>): boolean;\nexport function is(type: 'ge', ...args: Parameters<typeof ge>): boolean;\nexport function is(type: 'lt', ...args: Parameters<typeof lt>): boolean;\nexport function is(type: 'le', ...args: Parameters<typeof le>): boolean;\nexport function is(type: 'match', ...args: Parameters<typeof isMatch>): boolean;\nexport function is(type: 'empty', ...args: Parameters<typeof isEmpty>): boolean;\nexport function is(type: 'array', arg: unknown): arg is Array<unknown>;\nexport function is(type: 'string', arg: unknown): arg is string;\nexport function is(type: 'number', arg: unknown): arg is number;\nexport function is(type: 'object', arg: unknown): arg is object;\nexport function is(type: 'nil', arg: unknown): arg is null | undefined;\nexport function is(type: 'primitive', arg: unknown): arg is string | number | boolean;\nexport function is(type: isType, arg: unknown): boolean;\nexport function is(type: string, arg: unknown): boolean {\n assert(Boolean(type), 'Type must be provided', { args: { type }, type: Error });\n\n const compare = {\n defined: isDefined,\n empty: isEmpty,\n eq: (args: Parameters<typeof isEqual>) => isEqual(...args),\n even: isEven,\n ge: (args: Parameters<typeof ge>) => ge(...args),\n gt: (args: Parameters<typeof gt>) => gt(...args),\n le: (args: Parameters<typeof le>) => le(...args),\n lt: (args: Parameters<typeof lt>) => lt(...args),\n match: (args: Parameters<typeof isMatch>) => isMatch(...args),\n ne: (args: Parameters<typeof isEqual>) => !isEqual(...args),\n negative: isNegative,\n nil: isNil,\n odd: isOdd,\n positive: isPositive,\n regex: isRegex,\n within: (args: Parameters<typeof isWithin>) => isWithin(...args),\n zero: isZero,\n };\n\n return compare[type as keyof typeof compare]?.(arg) ?? typeOf(arg) === type;\n}\n"],"names":["is","type","arg","assert","isDefined","isEmpty","args","isEqual","isEven","ge","gt","le","lt","isMatch","isNegative","isNil","isOdd","isPositive","isRegex","isWithin","isZero","typeOf"],"mappings":";;;;;;;;;;;;;;;;;;AAiGO,SAASA,EAAGC,GAAcC,GAAuB;AACtD,SAAAC,EAAO,EAAQF,GAAO,yBAAyB,EAAE,MAAM,EAAE,MAAAA,EAAA,GAAQ,MAAM,OAAO,GAE9D;AAAA,IACd,SAASG;AAAA,IACT,OAAOC;AAAA,IACP,IAAI,CAACC,MAAqCC,EAAQ,GAAGD,CAAI;AAAA,IACzD,MAAME;AAAA,IACN,IAAI,CAACF,MAAgCG,EAAG,GAAGH,CAAI;AAAA,IAC/C,IAAI,CAACA,MAAgCI,EAAG,GAAGJ,CAAI;AAAA,IAC/C,IAAI,CAACA,MAAgCK,EAAG,GAAGL,CAAI;AAAA,IAC/C,IAAI,CAACA,MAAgCM,EAAG,GAAGN,CAAI;AAAA,IAC/C,OAAO,CAACA,MAAqCO,EAAQ,GAAGP,CAAI;AAAA,IAC5D,IAAI,CAACA,MAAqC,CAACC,EAAQ,GAAGD,CAAI;AAAA,IAC1D,UAAUQ;AAAA,IACV,KAAKC;AAAA,IACL,KAAKC;AAAA,IACL,UAAUC;AAAA,IACV,OAAOC;AAAA,IACP,QAAQ,CAACZ,MAAsCa,EAAS,GAAGb,CAAI;AAAA,IAC/D,MAAMc;AAAA,EAAA,EAGOnB,CAA4B,IAAIC,CAAG,KAAKmB,EAAOnB,CAAG,MAAMD;AACzE;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./isArray.cjs"),i=require("./isNil.cjs"),s=require("./isObject.cjs");function n(e){return i.isNil(e)||e===""||t.isArray(e)&&e.length===0||s.isObject(e)&&Object.keys(e).length===0}const c="Expected an empty value";exports.IS_EMPTY_ERROR_MSG=c;exports.isEmpty=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./isArray.cjs"),i=require("./isNil.cjs"),n=require("./isObject.cjs");function s(e){return i.isNil(e)||e===""?!0:t.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:n.isObject(e)?Object.keys(e).length===0:!1}const r="Expected an empty value";exports.IS_EMPTY_ERROR_MSG=r;exports.isEmpty=s;
2
2
  //# sourceMappingURL=isEmpty.cjs.map