@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,94 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/svg/displace.js
20
+ var displace_exports = {};
21
+ __export(displace_exports, {
22
+ displacePresets: () => displacePresets,
23
+ displaceSettings: () => displaceSettings
24
+ });
25
+ module.exports = __toCommonJS(displace_exports);
26
+ var displacePresets = {
27
+ // Ink bleeding into absorbent paper. Long wavelength, small push.
28
+ "wet-ink": {
29
+ type: "fractalNoise",
30
+ frequency: 0.015,
31
+ octaves: 3,
32
+ scale: 9,
33
+ seed: 2
34
+ },
35
+ // Ink bitten into paper tooth. The edge roughens without the letterform
36
+ // moving, so this is the only preset that survives at body sizes.
37
+ letterpress: {
38
+ type: "fractalNoise",
39
+ frequency: 0.09,
40
+ octaves: 1,
41
+ scale: 2,
42
+ seed: 5
43
+ },
44
+ // Air over heat. Anisotropic so the shimmer rises instead of swimming.
45
+ // Reads as nothing unless animated.
46
+ "heat-haze": {
47
+ type: "fractalNoise",
48
+ frequency: [4e-3, 0.02],
49
+ animateTo: [6e-3, 0.03],
50
+ duration: 8,
51
+ octaves: 2,
52
+ scale: 7,
53
+ seed: 11
54
+ },
55
+ // Tracking error on worn tape. A near-infinite horizontal wavelength against
56
+ // a very short vertical one is what tears rather than blobs.
57
+ "bad-tape": {
58
+ type: "turbulence",
59
+ frequency: [8e-4, 0.06],
60
+ animateTo: [8e-4, 0.09],
61
+ duration: 2.5,
62
+ octaves: 1,
63
+ scale: 14,
64
+ seed: 3
65
+ },
66
+ // Past the shred threshold on purpose.
67
+ shred: {
68
+ type: "turbulence",
69
+ frequency: 0.055,
70
+ octaves: 2,
71
+ scale: 32,
72
+ seed: 7
73
+ }
74
+ };
75
+ var format = (f) => Array.isArray(f) ? f.join(" ") : String(f);
76
+ function displaceSettings(opts = {}) {
77
+ const base = opts.preset && displacePresets[opts.preset] || displacePresets["wet-ink"];
78
+ const frequency = opts.frequency ?? base.frequency;
79
+ const animateTo = opts.animateTo ?? base.animateTo;
80
+ return {
81
+ type: opts.type ?? base.type,
82
+ frequency: format(frequency),
83
+ animateTo: animateTo ? format(animateTo) : null,
84
+ duration: opts.duration ?? base.duration ?? 6,
85
+ octaves: opts.octaves ?? base.octaves,
86
+ scale: opts.scale ?? base.scale,
87
+ seed: opts.seed ?? base.seed
88
+ };
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ displacePresets,
93
+ displaceSettings
94
+ });
@@ -0,0 +1,126 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/svg/index.js
20
+ var svg_exports = {};
21
+ __export(svg_exports, {
22
+ displacePresets: () => displacePresets,
23
+ displaceSettings: () => displaceSettings,
24
+ noiseColorMatrix: () => noiseColorMatrix,
25
+ noisePresets: () => noisePresets
26
+ });
27
+ module.exports = __toCommonJS(svg_exports);
28
+
29
+ // src/lib/svg/displace.js
30
+ var displacePresets = {
31
+ // Ink bleeding into absorbent paper. Long wavelength, small push.
32
+ "wet-ink": {
33
+ type: "fractalNoise",
34
+ frequency: 0.015,
35
+ octaves: 3,
36
+ scale: 9,
37
+ seed: 2
38
+ },
39
+ // Ink bitten into paper tooth. The edge roughens without the letterform
40
+ // moving, so this is the only preset that survives at body sizes.
41
+ letterpress: {
42
+ type: "fractalNoise",
43
+ frequency: 0.09,
44
+ octaves: 1,
45
+ scale: 2,
46
+ seed: 5
47
+ },
48
+ // Air over heat. Anisotropic so the shimmer rises instead of swimming.
49
+ // Reads as nothing unless animated.
50
+ "heat-haze": {
51
+ type: "fractalNoise",
52
+ frequency: [4e-3, 0.02],
53
+ animateTo: [6e-3, 0.03],
54
+ duration: 8,
55
+ octaves: 2,
56
+ scale: 7,
57
+ seed: 11
58
+ },
59
+ // Tracking error on worn tape. A near-infinite horizontal wavelength against
60
+ // a very short vertical one is what tears rather than blobs.
61
+ "bad-tape": {
62
+ type: "turbulence",
63
+ frequency: [8e-4, 0.06],
64
+ animateTo: [8e-4, 0.09],
65
+ duration: 2.5,
66
+ octaves: 1,
67
+ scale: 14,
68
+ seed: 3
69
+ },
70
+ // Past the shred threshold on purpose.
71
+ shred: {
72
+ type: "turbulence",
73
+ frequency: 0.055,
74
+ octaves: 2,
75
+ scale: 32,
76
+ seed: 7
77
+ }
78
+ };
79
+ var format = (f) => Array.isArray(f) ? f.join(" ") : String(f);
80
+ function displaceSettings(opts = {}) {
81
+ const base = opts.preset && displacePresets[opts.preset] || displacePresets["wet-ink"];
82
+ const frequency = opts.frequency ?? base.frequency;
83
+ const animateTo = opts.animateTo ?? base.animateTo;
84
+ return {
85
+ type: opts.type ?? base.type,
86
+ frequency: format(frequency),
87
+ animateTo: animateTo ? format(animateTo) : null,
88
+ duration: opts.duration ?? base.duration ?? 6,
89
+ octaves: opts.octaves ?? base.octaves,
90
+ scale: opts.scale ?? base.scale,
91
+ seed: opts.seed ?? base.seed
92
+ };
93
+ }
94
+
95
+ // src/lib/colors.js
96
+ function hexToRgb(hex) {
97
+ let h = hex.replace("#", "");
98
+ if (h.length === 3)
99
+ h = h.split("").map((c) => c + c).join("");
100
+ const int = parseInt(h, 16);
101
+ return {
102
+ r: +((int >> 16 & 255) / 255).toFixed(3),
103
+ g: +((int >> 8 & 255) / 255).toFixed(3),
104
+ b: +((int & 255) / 255).toFixed(3)
105
+ };
106
+ }
107
+
108
+ // src/lib/svg/noise.js
109
+ var noisePresets = {
110
+ black: "#000000",
111
+ sepia: "#a67c52",
112
+ synthwave: "#ff2bd6"
113
+ };
114
+ function noiseColorMatrix(color, strength) {
115
+ if (!color || color === "rainbow")
116
+ return `1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${strength} 0`;
117
+ const { r, g, b } = hexToRgb(noisePresets[color] ?? color);
118
+ return `0 0 0 0 ${r} 0 0 0 0 ${g} 0 0 0 0 ${b} 0 0 0 ${strength} 0`;
119
+ }
120
+ // Annotate the CommonJS export names for ESM import in node:
121
+ 0 && (module.exports = {
122
+ displacePresets,
123
+ displaceSettings,
124
+ noiseColorMatrix,
125
+ noisePresets
126
+ });
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/svg/noise.js
20
+ var noise_exports = {};
21
+ __export(noise_exports, {
22
+ noiseColorMatrix: () => noiseColorMatrix,
23
+ noisePresets: () => noisePresets
24
+ });
25
+ module.exports = __toCommonJS(noise_exports);
26
+
27
+ // src/lib/colors.js
28
+ function hexToRgb(hex) {
29
+ let h = hex.replace("#", "");
30
+ if (h.length === 3)
31
+ h = h.split("").map((c) => c + c).join("");
32
+ const int = parseInt(h, 16);
33
+ return {
34
+ r: +((int >> 16 & 255) / 255).toFixed(3),
35
+ g: +((int >> 8 & 255) / 255).toFixed(3),
36
+ b: +((int & 255) / 255).toFixed(3)
37
+ };
38
+ }
39
+
40
+ // src/lib/svg/noise.js
41
+ var noisePresets = {
42
+ black: "#000000",
43
+ sepia: "#a67c52",
44
+ synthwave: "#ff2bd6"
45
+ };
46
+ function noiseColorMatrix(color, strength) {
47
+ if (!color || color === "rainbow")
48
+ return `1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${strength} 0`;
49
+ const { r, g, b } = hexToRgb(noisePresets[color] ?? color);
50
+ return `0 0 0 0 ${r} 0 0 0 0 ${g} 0 0 0 0 ${b} 0 0 0 ${strength} 0`;
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ noiseColorMatrix,
55
+ noisePresets
56
+ });
@@ -0,0 +1,14 @@
1
+ function hexToRgb(hex) {
2
+ let h = hex.replace("#", "");
3
+ if (h.length === 3)
4
+ h = h.split("").map((c) => c + c).join("");
5
+ const int = parseInt(h, 16);
6
+ return {
7
+ r: +((int >> 16 & 255) / 255).toFixed(3),
8
+ g: +((int >> 8 & 255) / 255).toFixed(3),
9
+ b: +((int & 255) / 255).toFixed(3)
10
+ };
11
+ }
12
+ export {
13
+ hexToRgb
14
+ };
@@ -0,0 +1 @@
1
+ export * from "./status-text.js";
@@ -0,0 +1,72 @@
1
+ const statusTexts = {
2
+ 100: "Continue",
3
+ 101: "Switching Protocols",
4
+ 102: "Processing",
5
+ 103: "Early Hints",
6
+ 200: "OK",
7
+ 201: "Created",
8
+ 202: "Accepted",
9
+ 203: "Non-Authoritative Information",
10
+ 204: "No Content",
11
+ 205: "Reset Content",
12
+ 206: "Partial Content",
13
+ 207: "Multi-Status",
14
+ 208: "Already Reported",
15
+ 226: "IM Used",
16
+ 300: "Multiple Choices",
17
+ 301: "Moved Permanently",
18
+ 302: "Found",
19
+ 303: "See Other",
20
+ 304: "Not Modified",
21
+ 305: "Use Proxy",
22
+ 307: "Temporary Redirect",
23
+ 308: "Permanent Redirect",
24
+ 400: "Bad Request",
25
+ 401: "Unauthorized",
26
+ 402: "Payment Required",
27
+ 403: "Forbidden",
28
+ 404: "Not Found",
29
+ 405: "Method Not Allowed",
30
+ 406: "Not Acceptable",
31
+ 407: "Proxy Authentication Required",
32
+ 408: "Request Timeout",
33
+ 409: "Conflict",
34
+ 410: "Gone",
35
+ 411: "Length Required",
36
+ 412: "Precondition Failed",
37
+ 413: "Payload Too Large",
38
+ 414: "URI Too Long",
39
+ 415: "Unsupported Media Type",
40
+ 416: "Range Not Satisfiable",
41
+ 417: "Expectation Failed",
42
+ 418: "I'm a Teapot",
43
+ 421: "Misdirected Request",
44
+ 422: "Unprocessable Entity",
45
+ 423: "Locked",
46
+ 424: "Failed Dependency",
47
+ 425: "Too Early",
48
+ 426: "Upgrade Required",
49
+ 428: "Precondition Required",
50
+ 429: "Too Many Requests",
51
+ 431: "Request Header Fields Too Large",
52
+ 451: "Unavailable For Legal Reasons",
53
+ 500: "Internal Server Error",
54
+ 501: "Not Implemented",
55
+ 502: "Bad Gateway",
56
+ 503: "Service Unavailable",
57
+ 504: "Gateway Timeout",
58
+ 505: "HTTP Version Not Supported",
59
+ 506: "Variant Also Negotiates",
60
+ 507: "Insufficient Storage",
61
+ 508: "Loop Detected",
62
+ 509: "Bandwidth Limit Exceeded",
63
+ 510: "Not Extended",
64
+ 511: "Network Authentication Required"
65
+ };
66
+ function statusText(code) {
67
+ return statusTexts[code];
68
+ }
69
+ export {
70
+ statusText,
71
+ statusTexts
72
+ };
@@ -1,14 +1,17 @@
1
1
  export * from "./arrays/index.js";
2
2
  export * from "./auth/index.js";
3
3
  export * from "./checks.js";
4
+ export * from "./colors.js";
4
5
  export * from "./date/index.js";
5
6
  export * from "./form/index.js";
6
7
  export * from "./functions/index.js";
7
8
  export * from "./hash.js";
9
+ export * from "./http/index.js";
8
10
  export * from "./numbers/index.js";
9
11
  export * from "./objects/index.js";
10
12
  export * from "./promises/index.js";
11
13
  export * from "./sse.js";
12
14
  export * from "./strings/index.js";
13
15
  export * from "./style/index.js";
16
+ export * from "./svg/index.js";
14
17
  export * from "./symbols/index.js";
@@ -1,11 +1,3 @@
1
1
  export * from "./math.js";
2
- function splitUnit(string) {
3
- if (typeof string === "number") return [string, null];
4
- const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
5
- const match = string.match(regex);
6
- if (match) return [parseFloat(match[1]), match[2]];
7
- return [parseFloat(string), null];
8
- }
9
- export {
10
- splitUnit
11
- };
2
+ export * from "./random.js";
3
+ export * from "./split-unit.js";
@@ -0,0 +1,10 @@
1
+ function seededRandom(seed = 1) {
2
+ let state = seed >>> 0;
3
+ return () => {
4
+ state = state * 1664525 + 1013904223 >>> 0;
5
+ return state / 4294967296;
6
+ };
7
+ }
8
+ export {
9
+ seededRandom
10
+ };
@@ -0,0 +1,10 @@
1
+ function splitUnit(string) {
2
+ if (typeof string === "number") return [string, null];
3
+ const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
4
+ const match = string.match(regex);
5
+ if (match) return [parseFloat(match[1]), match[2]];
6
+ return [parseFloat(string), null];
7
+ }
8
+ export {
9
+ splitUnit
10
+ };
@@ -1,11 +1,11 @@
1
- import statuses from "statuses";
2
1
  import { omitEmpty } from "../objects/omit-empty.js";
2
+ import { statusText as httpStatusText } from "../http/status-text.js";
3
3
  function reject(props, { includeStack = true } = {}) {
4
4
  const { status, statusText, body, message } = props;
5
5
  const e = new Error();
6
6
  const err = {
7
7
  status,
8
- statusText: statusText || status && statuses(status),
8
+ statusText: statusText || status && httpStatusText(status),
9
9
  body,
10
10
  message,
11
11
  stack: includeStack && e.stack