@splendidlabz/utils 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/cjs/dom/font-size.cjs +1 -1
  2. package/dist/cjs/dom/index.cjs +1 -1
  3. package/dist/cjs/lib/colors.cjs +39 -0
  4. package/dist/cjs/lib/date/index.cjs +1 -1
  5. package/dist/cjs/lib/date/time.cjs +1 -1
  6. package/dist/cjs/lib/http/index.cjs +100 -0
  7. package/dist/cjs/lib/http/status-text.cjs +98 -0
  8. package/dist/cjs/lib/index.cjs +584 -11
  9. package/dist/cjs/lib/numbers/index.cjs +12 -1
  10. package/dist/cjs/lib/numbers/random.cjs +35 -0
  11. package/dist/cjs/lib/numbers/split-unit.cjs +35 -0
  12. package/dist/cjs/lib/promises/index.cjs +72 -15
  13. package/dist/cjs/lib/promises/reject.cjs +72 -13
  14. package/dist/cjs/lib/strings/index.cjs +368 -6
  15. package/dist/cjs/lib/strings/pluralize.cjs +372 -14
  16. package/dist/cjs/lib/strings/query-string.cjs +0 -6
  17. package/dist/cjs/lib/style/index.cjs +35 -1
  18. package/dist/cjs/lib/style/scatter.cjs +60 -0
  19. package/dist/cjs/lib/style/to-style-string.cjs +64 -0
  20. package/dist/cjs/lib/svg/displace.cjs +94 -0
  21. package/dist/cjs/lib/svg/index.cjs +126 -0
  22. package/dist/cjs/lib/svg/noise.cjs +56 -0
  23. package/dist/esm/lib/colors.js +14 -0
  24. package/dist/esm/lib/http/index.js +1 -0
  25. package/dist/esm/lib/http/status-text.js +72 -0
  26. package/dist/esm/lib/index.js +3 -0
  27. package/dist/esm/lib/numbers/index.js +2 -10
  28. package/dist/esm/lib/numbers/random.js +10 -0
  29. package/dist/esm/lib/numbers/split-unit.js +10 -0
  30. package/dist/esm/lib/promises/reject.js +2 -2
  31. package/dist/esm/lib/strings/pluralize.js +366 -3
  32. package/dist/esm/lib/strings/query-string.js +0 -5
  33. package/dist/esm/lib/style/index.js +2 -12
  34. package/dist/esm/lib/style/scatter.js +25 -0
  35. package/dist/esm/lib/style/to-style-string.js +12 -0
  36. package/dist/esm/lib/svg/displace.js +68 -0
  37. package/dist/esm/lib/svg/index.js +2 -0
  38. package/dist/esm/lib/svg/noise.js +16 -0
  39. package/dist/types/dom/font-size.d.cts +1 -1
  40. package/dist/types/lib/colors.d.cts +12 -0
  41. package/dist/types/lib/http/index.d.cts +1 -0
  42. package/dist/types/lib/http/status-text.d.cts +73 -0
  43. package/dist/types/lib/index.d.cts +11 -5
  44. package/dist/types/lib/numbers/index.d.cts +2 -4
  45. package/dist/types/lib/numbers/random.d.cts +14 -0
  46. package/dist/types/lib/numbers/split-unit.d.cts +8 -0
  47. package/dist/types/lib/strings/index.d.cts +2 -2
  48. package/dist/types/lib/strings/pluralize.d.cts +24 -2
  49. package/dist/types/lib/strings/query-string.d.cts +1 -2
  50. package/dist/types/lib/style/index.d.cts +2 -3
  51. package/dist/types/lib/style/scatter.d.cts +48 -0
  52. package/dist/types/lib/style/to-style-string.d.cts +8 -0
  53. package/dist/types/lib/svg/displace.d.cts +54 -0
  54. package/dist/types/lib/svg/index.d.cts +2 -0
  55. package/dist/types/lib/svg/noise.d.cts +24 -0
  56. package/dist/types/node/dirname.d.cts +2 -2
  57. package/dist/types/node/file.d.cts +1 -1
  58. package/dist/types/node/hash.d.cts +1 -1
  59. package/dist/types/node/pkce.d.cts +4 -4
  60. package/dist/types/node/random-string.d.cts +1 -1
  61. package/dist/types/node/uuid.d.cts +1 -1
  62. package/package.json +3 -6
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Splits a value into its numeric part and unit.
3
+ * @param {string|number} string - Value like `'2rem'`, `'30 days'`, or a plain number.
4
+ * @returns {[number, string|null]} `[value, unit]` — unit is null when there isn't one.
5
+ */
6
+ declare function splitUnit(string: string | number): [number, string | null];
7
+
8
+ export { splitUnit };
@@ -1,5 +1,5 @@
1
1
  export { toCamel, toKebab, toLower, toPascal, toSentence, toSlug, toTitle, toUpper } from './convert-case/convert-case.cjs';
2
2
  export { markdown, treatMarkdownWhitespace } from './markdown.cjs';
3
3
  export { parseFullName } from './name.cjs';
4
- export { pluralize } from './pluralize.cjs';
5
- export { parseQueryString, plural, stripNumbers, toQueryString } from './query-string.cjs';
4
+ export { createPluralize, isPlural, isSingular, plural, pluralize, singular } from './pluralize.cjs';
5
+ export { parseQueryString, stripNumbers, toQueryString } from './query-string.cjs';
@@ -1,3 +1,25 @@
1
- declare const pluralize: any;
1
+ /**
2
+ * Create a pluralizer with its own rule tables. Config rules are appended to
3
+ * the English base and take precedence (newest matching rule wins).
4
+ *
5
+ * @param {Object} [config]
6
+ * @param {Array} [config.plural] - `[rule, replacement]` pairs.
7
+ * @param {Array} [config.singular] - `[rule, replacement]` pairs.
8
+ * @param {Array} [config.irregular] - `[single, plural]` pairs.
9
+ * @param {Array} [config.uncountable] - words or regexes with no plural.
10
+ * @return {Function} A callable `pluralize` with `.plural`, `.singular`,
11
+ * `.isPlural`, `.isSingular` attached.
12
+ */
13
+ declare function createPluralize(config?: {
14
+ plural?: any[];
15
+ singular?: any[];
16
+ irregular?: any[];
17
+ uncountable?: any[];
18
+ }): Function;
19
+ declare const pluralize: Function;
20
+ declare const plural: any;
21
+ declare const singular: any;
22
+ declare const isPlural: any;
23
+ declare const isSingular: any;
2
24
 
3
- export { pluralize };
25
+ export { createPluralize, isPlural, isSingular, plural, pluralize, singular };
@@ -13,7 +13,6 @@ declare function toQueryString(object: any): string;
13
13
  * @returns {Object}
14
14
  */
15
15
  declare function parseQueryString(string?: string): any;
16
- declare function plural(count: any, noun: any, suffix?: string): string;
17
16
  declare function stripNumbers(string: any): any;
18
17
 
19
- export { parseQueryString, plural, stripNumbers, toQueryString };
18
+ export { parseQueryString, stripNumbers, toQueryString };
@@ -1,3 +1,2 @@
1
- declare function toStyleString(style: any): string;
2
-
3
- export { toStyleString };
1
+ export { ScatterItem, scatter } from './scatter.cjs';
2
+ export { toStyleString } from './to-style-string.cjs';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @typedef {Object} ScatterItem
3
+ * @property {number} x Horizontal offset, in % of the element's own size
4
+ * @property {number} y Vertical offset, in % of the element's own size
5
+ * @property {number} rotation Rotation in degrees
6
+ * @property {string} transform Ready-to-use CSS transform value
7
+ */
8
+ /**
9
+ * Places elements off a perfect grid so they read as laid down by hand rather
10
+ * than generated. Offsets are in % so they scale with the element.
11
+ *
12
+ * Seeded, so the same seed always produces the same arrangement — which is what
13
+ * keeps SSR and hydration in agreement.
14
+ *
15
+ * @param {number} count Number of elements to place
16
+ * @param {Object} [options]
17
+ * @param {number} [options.seed] Change for a different arrangement
18
+ * @param {number} [options.spread] Max offset, in % of the element's own size
19
+ * @param {number} [options.rotation] Max rotation in degrees
20
+ * @param {number} [options.amount] 0–1 dial over both spread and rotation
21
+ * @returns {ScatterItem[]}
22
+ */
23
+ declare function scatter(count: number, options?: {
24
+ seed?: number;
25
+ spread?: number;
26
+ rotation?: number;
27
+ amount?: number;
28
+ }): ScatterItem[];
29
+ type ScatterItem = {
30
+ /**
31
+ * Horizontal offset, in % of the element's own size
32
+ */
33
+ x: number;
34
+ /**
35
+ * Vertical offset, in % of the element's own size
36
+ */
37
+ y: number;
38
+ /**
39
+ * Rotation in degrees
40
+ */
41
+ rotation: number;
42
+ /**
43
+ * Ready-to-use CSS transform value
44
+ */
45
+ transform: string;
46
+ };
47
+
48
+ export { type ScatterItem, scatter };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts a style object into a CSS style string. Passes strings through untouched.
3
+ * @param {string|Object} style - Style string or object of camelCase/custom properties.
4
+ * @returns {string|null} CSS style string, or null if no style given.
5
+ */
6
+ declare function toStyleString(style: string | any): string | null;
7
+
8
+ export { toStyleString };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Merge a preset with explicit overrides. Explicit always wins.
3
+ * @param {Partial<DisplacePreset> & { preset?: string }} [opts]
4
+ */
5
+ declare function displaceSettings(opts?: Partial<DisplacePreset> & {
6
+ preset?: string;
7
+ }): {
8
+ type: string;
9
+ frequency: string;
10
+ animateTo: string;
11
+ duration: number;
12
+ octaves: number;
13
+ scale: number;
14
+ seed: number;
15
+ };
16
+ /**
17
+ * Two numbers govern the effect.
18
+ *
19
+ * frequency — wavelength of the distortion, roughly (1 / frequency) px
20
+ * scale — how far each pixel is pushed
21
+ *
22
+ * Their ratio decides the outcome. Once scale approaches the wavelength,
23
+ * neighbouring pixels displace past each other and the form comes apart.
24
+ *
25
+ * scale < wavelength × 0.25 warp — shape survives, edges soften
26
+ * scale ≈ wavelength × 0.5 distress — edges tear, holes open
27
+ * scale > wavelength shred — shape is destroyed
28
+ *
29
+ * type='fractalNoise' is smooth and symmetric — warps.
30
+ * type='turbulence' takes the absolute value, so it creases — wisps and tears.
31
+ */
32
+ /**
33
+ * @typedef {Object} DisplacePreset
34
+ * @property {string} type
35
+ * @property {number|number[]} frequency
36
+ * @property {number|number[]} [animateTo]
37
+ * @property {number} [duration]
38
+ * @property {number} octaves
39
+ * @property {number} scale
40
+ * @property {number} seed
41
+ */
42
+ /** @type {Record<string, DisplacePreset>} */
43
+ declare const displacePresets: Record<string, DisplacePreset>;
44
+ type DisplacePreset = {
45
+ type: string;
46
+ frequency: number | number[];
47
+ animateTo?: number | number[];
48
+ duration?: number;
49
+ octaves: number;
50
+ scale: number;
51
+ seed: number;
52
+ };
53
+
54
+ export { type DisplacePreset, displacePresets, displaceSettings };
@@ -0,0 +1,2 @@
1
+ export { DisplacePreset, displacePresets, displaceSettings } from './displace.cjs';
2
+ export { noiseColorMatrix, noisePresets } from './noise.cjs';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Build the feColorMatrix values for a noise colour.
3
+ *
4
+ * feTurbulence outputs independent noise per RGB channel, so colour is the
5
+ * natural state — the matrix decides what survives:
6
+ * - no color or 'rainbow' → RGB passes through: coloured static (default)
7
+ * - preset name ('black', 'sepia', 'synthwave') or hex → constant tint,
8
+ * alpha still noise-driven
9
+ *
10
+ * strength scales the per-pixel alpha. 0–1 fades the grain; above 1 the
11
+ * alpha saturates, so the grain gets denser rather than stronger.
12
+ *
13
+ * @param {string} [color] - 'rainbow' (default), a preset name, or a hex colour.
14
+ * @param {number} strength - Per-pixel alpha multiplier.
15
+ * @returns {string}
16
+ */
17
+ declare function noiseColorMatrix(color?: string, strength: number): string;
18
+ declare namespace noisePresets {
19
+ let black: string;
20
+ let sepia: string;
21
+ let synthwave: string;
22
+ }
23
+
24
+ export { noiseColorMatrix, noisePresets };
@@ -3,7 +3,7 @@
3
3
  * @param url — import.meta.url
4
4
  * @returns
5
5
  */
6
- declare function __dirname$1(url: any): string;
7
- declare function dirname(url: any): string;
6
+ declare function __dirname$1(url: any): any;
7
+ declare function dirname(url: any): any;
8
8
 
9
9
  export { __dirname$1 as __dirname, dirname };
@@ -1,4 +1,4 @@
1
- declare function mkdir(path: any): Promise<string>;
1
+ declare function mkdir(path: any): Promise<any>;
2
2
  declare function copyFile(from: any, to: any): Promise<void>;
3
3
 
4
4
  export { copyFile, mkdir };
@@ -1,3 +1,3 @@
1
- declare function sha256Hash(string: any): string;
1
+ declare function sha256Hash(string: any): any;
2
2
 
3
3
  export { sha256Hash };
@@ -1,7 +1,7 @@
1
1
  declare function PKCE(): Promise<{
2
- state: string;
3
- code_verifier: string;
4
- code_challenge: string;
2
+ state: any;
3
+ code_verifier: any;
4
+ code_challenge: any;
5
5
  code_challenge_method: string;
6
6
  }>;
7
7
  /**
@@ -9,6 +9,6 @@ declare function PKCE(): Promise<{
9
9
  * @param {string} verifier
10
10
  * @returns string
11
11
  */
12
- declare function getCodeChallenge(verifier: string): string;
12
+ declare function getCodeChallenge(verifier: string): any;
13
13
 
14
14
  export { PKCE, getCodeChallenge };
@@ -1,3 +1,3 @@
1
- declare function randomString(length?: number): string;
1
+ declare function randomString(length?: number): any;
2
2
 
3
3
  export { randomString };
@@ -1,3 +1,3 @@
1
- declare function uuid(): `${string}-${string}-${string}-${string}-${string}`;
1
+ declare function uuid(): any;
2
2
 
3
3
  export { uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splendidlabz/utils",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "homepage": "https://splendidlabz.com/docs/utils",
@@ -64,13 +64,10 @@
64
64
  "marked": "^18.0.2",
65
65
  "marked-gfm-heading-id": "^4.1.4",
66
66
  "marked-mangle": "^1.1.13",
67
- "pluralize": "^8.0.0",
68
- "sanitize-html": "^2.17.3",
69
- "statuses": "^2.0.2"
67
+ "sanitize-html": "^2.17.3"
70
68
  },
71
69
  "devDependencies": {
72
- "@splendidlabz/eslint-config": "2.1.5",
73
- "jsdom": "^29.0.2",
70
+ "@splendidlabz/eslint-config": "2.1.6",
74
71
  "np": "^11.1.0",
75
72
  "tsup": "^8.5.1",
76
73
  "typescript": "^6.0.3",