@ciwergrp/nuxid 1.0.2-release

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 (145) hide show
  1. package/README.md +119 -0
  2. package/bin/kiban.mjs +41 -0
  3. package/console/request.mjs +337 -0
  4. package/dist/module.d.mts +188 -0
  5. package/dist/module.json +9 -0
  6. package/dist/module.mjs +439 -0
  7. package/dist/runtime/form.d.ts +21 -0
  8. package/dist/runtime/form.js +161 -0
  9. package/dist/runtime/helper/array/collapse.d.ts +1 -0
  10. package/dist/runtime/helper/array/collapse.js +9 -0
  11. package/dist/runtime/helper/array/crossJoin.d.ts +1 -0
  12. package/dist/runtime/helper/array/crossJoin.js +17 -0
  13. package/dist/runtime/helper/array/every.d.ts +1 -0
  14. package/dist/runtime/helper/array/every.js +3 -0
  15. package/dist/runtime/helper/array/first.d.ts +1 -0
  16. package/dist/runtime/helper/array/first.js +11 -0
  17. package/dist/runtime/helper/array/flatten.d.ts +1 -0
  18. package/dist/runtime/helper/array/flatten.js +14 -0
  19. package/dist/runtime/helper/array/index.d.ts +46 -0
  20. package/dist/runtime/helper/array/index.js +69 -0
  21. package/dist/runtime/helper/array/join.d.ts +1 -0
  22. package/dist/runtime/helper/array/join.js +11 -0
  23. package/dist/runtime/helper/array/last.d.ts +1 -0
  24. package/dist/runtime/helper/array/last.js +11 -0
  25. package/dist/runtime/helper/array/map.d.ts +1 -0
  26. package/dist/runtime/helper/array/map.js +3 -0
  27. package/dist/runtime/helper/array/mapSpread.d.ts +1 -0
  28. package/dist/runtime/helper/array/mapSpread.js +3 -0
  29. package/dist/runtime/helper/array/partition.d.ts +1 -0
  30. package/dist/runtime/helper/array/partition.js +12 -0
  31. package/dist/runtime/helper/array/random.d.ts +1 -0
  32. package/dist/runtime/helper/array/random.js +19 -0
  33. package/dist/runtime/helper/array/reject.d.ts +1 -0
  34. package/dist/runtime/helper/array/reject.js +3 -0
  35. package/dist/runtime/helper/array/shuffle.d.ts +1 -0
  36. package/dist/runtime/helper/array/shuffle.js +8 -0
  37. package/dist/runtime/helper/array/sole.d.ts +1 -0
  38. package/dist/runtime/helper/array/sole.js +7 -0
  39. package/dist/runtime/helper/array/some.d.ts +1 -0
  40. package/dist/runtime/helper/array/some.js +3 -0
  41. package/dist/runtime/helper/array/sort.d.ts +1 -0
  42. package/dist/runtime/helper/array/sort.js +4 -0
  43. package/dist/runtime/helper/array/sortDesc.d.ts +1 -0
  44. package/dist/runtime/helper/array/sortDesc.js +9 -0
  45. package/dist/runtime/helper/array/take.d.ts +1 -0
  46. package/dist/runtime/helper/array/take.js +9 -0
  47. package/dist/runtime/helper/array/where.d.ts +1 -0
  48. package/dist/runtime/helper/array/where.js +3 -0
  49. package/dist/runtime/helper/array/whereNotNull.d.ts +1 -0
  50. package/dist/runtime/helper/array/whereNotNull.js +3 -0
  51. package/dist/runtime/helper/array/wrap.d.ts +1 -0
  52. package/dist/runtime/helper/array/wrap.js +6 -0
  53. package/dist/runtime/helper/index.d.ts +4 -0
  54. package/dist/runtime/helper/index.js +4 -0
  55. package/dist/runtime/helper/number/clamp.d.ts +1 -0
  56. package/dist/runtime/helper/number/clamp.js +3 -0
  57. package/dist/runtime/helper/number/currency.d.ts +1 -0
  58. package/dist/runtime/helper/number/currency.js +14 -0
  59. package/dist/runtime/helper/number/fileSize.d.ts +1 -0
  60. package/dist/runtime/helper/number/fileSize.js +12 -0
  61. package/dist/runtime/helper/number/format.d.ts +1 -0
  62. package/dist/runtime/helper/number/format.js +12 -0
  63. package/dist/runtime/helper/number/humanize.d.ts +5 -0
  64. package/dist/runtime/helper/number/humanize.js +39 -0
  65. package/dist/runtime/helper/number/index.d.ts +37 -0
  66. package/dist/runtime/helper/number/index.js +60 -0
  67. package/dist/runtime/helper/number/intl.d.ts +5 -0
  68. package/dist/runtime/helper/number/intl.js +32 -0
  69. package/dist/runtime/helper/number/ordinal.d.ts +1 -0
  70. package/dist/runtime/helper/number/ordinal.js +26 -0
  71. package/dist/runtime/helper/number/pairs.d.ts +1 -0
  72. package/dist/runtime/helper/number/pairs.js +11 -0
  73. package/dist/runtime/helper/number/parse.d.ts +4 -0
  74. package/dist/runtime/helper/number/parse.js +19 -0
  75. package/dist/runtime/helper/number/percentage.d.ts +1 -0
  76. package/dist/runtime/helper/number/percentage.js +14 -0
  77. package/dist/runtime/helper/number/spell.d.ts +2 -0
  78. package/dist/runtime/helper/number/spell.js +145 -0
  79. package/dist/runtime/helper/number/state.d.ts +1 -0
  80. package/dist/runtime/helper/number/state.js +8 -0
  81. package/dist/runtime/helper/number/trim.d.ts +1 -0
  82. package/dist/runtime/helper/number/trim.js +3 -0
  83. package/dist/runtime/helper/object/add.d.ts +2 -0
  84. package/dist/runtime/helper/object/add.js +8 -0
  85. package/dist/runtime/helper/object/dot.d.ts +1 -0
  86. package/dist/runtime/helper/object/dot.js +19 -0
  87. package/dist/runtime/helper/object/except.d.ts +2 -0
  88. package/dist/runtime/helper/object/except.js +10 -0
  89. package/dist/runtime/helper/object/forget.d.ts +2 -0
  90. package/dist/runtime/helper/object/forget.js +24 -0
  91. package/dist/runtime/helper/object/get.d.ts +2 -0
  92. package/dist/runtime/helper/object/get.js +15 -0
  93. package/dist/runtime/helper/object/has.d.ts +2 -0
  94. package/dist/runtime/helper/object/has.js +5 -0
  95. package/dist/runtime/helper/object/index.d.ts +22 -0
  96. package/dist/runtime/helper/object/index.js +33 -0
  97. package/dist/runtime/helper/object/only.d.ts +2 -0
  98. package/dist/runtime/helper/object/only.js +12 -0
  99. package/dist/runtime/helper/object/set.d.ts +2 -0
  100. package/dist/runtime/helper/object/set.js +23 -0
  101. package/dist/runtime/helper/object/undot.d.ts +1 -0
  102. package/dist/runtime/helper/object/undot.js +8 -0
  103. package/dist/runtime/helper/object/utils.d.ts +3 -0
  104. package/dist/runtime/helper/object/utils.js +10 -0
  105. package/dist/runtime/helper/state.d.ts +6 -0
  106. package/dist/runtime/helper/state.js +50 -0
  107. package/dist/runtime/helper/string/basic.d.ts +7 -0
  108. package/dist/runtime/helper/string/basic.js +42 -0
  109. package/dist/runtime/helper/string/bounds.d.ts +6 -0
  110. package/dist/runtime/helper/string/bounds.js +42 -0
  111. package/dist/runtime/helper/string/case.d.ts +9 -0
  112. package/dist/runtime/helper/string/case.js +50 -0
  113. package/dist/runtime/helper/string/index.d.ts +57 -0
  114. package/dist/runtime/helper/string/index.js +100 -0
  115. package/dist/runtime/helper/string/locale.d.ts +1 -0
  116. package/dist/runtime/helper/string/locale.js +1 -0
  117. package/dist/runtime/helper/string/match.d.ts +4 -0
  118. package/dist/runtime/helper/string/match.js +15 -0
  119. package/dist/runtime/helper/string/pad.d.ts +3 -0
  120. package/dist/runtime/helper/string/pad.js +12 -0
  121. package/dist/runtime/helper/string/plural.d.ts +3 -0
  122. package/dist/runtime/helper/string/plural.js +16 -0
  123. package/dist/runtime/helper/string/replace.d.ts +4 -0
  124. package/dist/runtime/helper/string/replace.js +25 -0
  125. package/dist/runtime/helper/string/slug.d.ts +1 -0
  126. package/dist/runtime/helper/string/slug.js +8 -0
  127. package/dist/runtime/helper/string/transliterate.d.ts +2 -0
  128. package/dist/runtime/helper/string/transliterate.js +8 -0
  129. package/dist/runtime/helper/string/words.d.ts +2 -0
  130. package/dist/runtime/helper/string/words.js +13 -0
  131. package/dist/runtime/lodash.d.ts +1 -0
  132. package/dist/runtime/lodash.js +1 -0
  133. package/dist/runtime/pinia/composables.d.ts +2 -0
  134. package/dist/runtime/pinia/composables.js +3 -0
  135. package/dist/runtime/pinia/payload-plugin.d.ts +5 -0
  136. package/dist/runtime/pinia/payload-plugin.js +15 -0
  137. package/dist/runtime/pinia/plugin.d.ts +6 -0
  138. package/dist/runtime/pinia/plugin.js +22 -0
  139. package/dist/runtime/plugin.d.ts +2 -0
  140. package/dist/runtime/plugin.js +4 -0
  141. package/dist/runtime/server/tsconfig.json +3 -0
  142. package/dist/runtime/validator.d.ts +13 -0
  143. package/dist/runtime/validator.js +445 -0
  144. package/dist/types.d.mts +11 -0
  145. package/package.json +90 -0
@@ -0,0 +1,14 @@
1
+ import { defaultLocale } from "./state.js";
2
+ export function percentage(number, precision = 0, maxPrecision, locale) {
3
+ const resolvedLocale = locale ?? defaultLocale();
4
+ const options = {
5
+ style: "percent"
6
+ };
7
+ if (maxPrecision !== null && maxPrecision !== void 0) {
8
+ options.maximumFractionDigits = maxPrecision;
9
+ } else {
10
+ options.minimumFractionDigits = precision;
11
+ options.maximumFractionDigits = precision;
12
+ }
13
+ return new Intl.NumberFormat(resolvedLocale, options).format(number / 100);
14
+ }
@@ -0,0 +1,2 @@
1
+ export declare function spell(number: number, locale?: string | null, after?: number | null, until?: number | null): string;
2
+ export declare function spellOrdinal(number: number, locale?: string | null): string;
@@ -0,0 +1,145 @@
1
+ import { defaultLocale } from "./state.js";
2
+ import { format } from "./format.js";
3
+ const belowTwenty = [
4
+ "zero",
5
+ "one",
6
+ "two",
7
+ "three",
8
+ "four",
9
+ "five",
10
+ "six",
11
+ "seven",
12
+ "eight",
13
+ "nine",
14
+ "ten",
15
+ "eleven",
16
+ "twelve",
17
+ "thirteen",
18
+ "fourteen",
19
+ "fifteen",
20
+ "sixteen",
21
+ "seventeen",
22
+ "eighteen",
23
+ "nineteen"
24
+ ];
25
+ const tens = [
26
+ "",
27
+ "",
28
+ "twenty",
29
+ "thirty",
30
+ "forty",
31
+ "fifty",
32
+ "sixty",
33
+ "seventy",
34
+ "eighty",
35
+ "ninety"
36
+ ];
37
+ const scales = ["", "thousand", "million", "billion", "trillion", "quadrillion"];
38
+ export function spell(number, locale, after, until) {
39
+ if (after !== null && after !== void 0 && number <= after) {
40
+ return format(number, void 0, void 0, locale ?? defaultLocale());
41
+ }
42
+ if (until !== null && until !== void 0 && number >= until) {
43
+ return format(number, void 0, void 0, locale ?? defaultLocale());
44
+ }
45
+ return numberToWords(number, locale ?? defaultLocale());
46
+ }
47
+ export function spellOrdinal(number, locale) {
48
+ const resolvedLocale = locale ?? defaultLocale();
49
+ const cardinal = numberToWords(number, resolvedLocale);
50
+ return convertToOrdinalWords(cardinal);
51
+ }
52
+ function numberToWords(value, _locale) {
53
+ const isNegative = value < 0;
54
+ const absolute = Math.abs(value);
55
+ const [integerPart, fractionPart] = absolute.toString().split(".");
56
+ const integerWords = integerToWords(Number.parseInt(integerPart, 10));
57
+ const fractionWords = fractionPart ? fractionPart.split("").map((digit) => belowTwenty[Number(digit)]) : [];
58
+ let words = integerWords;
59
+ if (fractionWords.length) {
60
+ words = `${integerWords} point ${fractionWords.join(" ")}`;
61
+ }
62
+ if (isNegative) {
63
+ words = `negative ${words}`;
64
+ }
65
+ return words;
66
+ }
67
+ function integerToWords(value) {
68
+ if (value === 0) {
69
+ return belowTwenty[0];
70
+ }
71
+ const chunks = [];
72
+ let remaining = value;
73
+ while (remaining > 0) {
74
+ chunks.push(remaining % 1e3);
75
+ remaining = Math.floor(remaining / 1e3);
76
+ }
77
+ const words = [];
78
+ for (let index = 0; index < chunks.length; index++) {
79
+ const chunk = chunks[index];
80
+ if (chunk === 0) {
81
+ continue;
82
+ }
83
+ const chunkWords = chunkToWords(chunk);
84
+ const scale = scales[index];
85
+ words.unshift(scale ? `${chunkWords} ${scale}` : chunkWords);
86
+ }
87
+ return words.join(" ");
88
+ }
89
+ function chunkToWords(value) {
90
+ const words = [];
91
+ const hundreds = Math.floor(value / 100);
92
+ const remainder = value % 100;
93
+ if (hundreds > 0) {
94
+ words.push(`${belowTwenty[hundreds]} hundred`);
95
+ }
96
+ if (remainder > 0) {
97
+ if (remainder < 20) {
98
+ words.push(belowTwenty[remainder]);
99
+ } else {
100
+ const tensPlace = Math.floor(remainder / 10);
101
+ const unitsPlace = remainder % 10;
102
+ if (tens[tensPlace]) {
103
+ words.push(unitsPlace ? `${tens[tensPlace]}-${belowTwenty[unitsPlace]}` : tens[tensPlace]);
104
+ }
105
+ }
106
+ }
107
+ return words.join(" ");
108
+ }
109
+ function convertToOrdinalWords(value) {
110
+ const parts = value.split(" ");
111
+ if (!parts.length) {
112
+ return value;
113
+ }
114
+ const last = parts.pop();
115
+ const hyphenParts = last.split("-");
116
+ const lastToken = hyphenParts.pop();
117
+ const ordinal = toOrdinalWord(lastToken);
118
+ const rebuiltLast = hyphenParts.length ? [...hyphenParts, ordinal].join("-") : ordinal;
119
+ return [...parts, rebuiltLast].join(" ");
120
+ }
121
+ function toOrdinalWord(word) {
122
+ const normalized = word.toLowerCase();
123
+ const irregular = {
124
+ one: "first",
125
+ two: "second",
126
+ three: "third",
127
+ five: "fifth",
128
+ eight: "eighth",
129
+ nine: "ninth",
130
+ twelve: "twelfth"
131
+ };
132
+ if (irregular[normalized]) {
133
+ return irregular[normalized];
134
+ }
135
+ if (normalized.endsWith("y")) {
136
+ return `${normalized.slice(0, -1)}ieth`;
137
+ }
138
+ if (normalized.endsWith("ve")) {
139
+ return `${normalized.slice(0, -2)}fth`;
140
+ }
141
+ if (normalized.endsWith("ht")) {
142
+ return `${normalized}h`;
143
+ }
144
+ return `${normalized}th`;
145
+ }
@@ -0,0 +1 @@
1
+ export { defaultCurrency, defaultLocale, useCurrency, useLocale, withCurrency, withLocale, } from '../state.js';
@@ -0,0 +1,8 @@
1
+ export {
2
+ defaultCurrency,
3
+ defaultLocale,
4
+ useCurrency,
5
+ useLocale,
6
+ withCurrency,
7
+ withLocale
8
+ } from "../state.js";
@@ -0,0 +1 @@
1
+ export declare function trim(number: number): number;
@@ -0,0 +1,3 @@
1
+ export function trim(number) {
2
+ return Number.parseFloat(Number(number).toString());
3
+ }
@@ -0,0 +1,2 @@
1
+ import type { Path } from './utils.js';
2
+ export declare function add<T extends Record<string, any>>(target: T, path: Path, value: any): T;
@@ -0,0 +1,8 @@
1
+ import { get } from "./get.js";
2
+ import { set } from "./set.js";
3
+ export function add(target, path, value) {
4
+ if (get(target, path) === void 0 || get(target, path) === null) {
5
+ set(target, path, value);
6
+ }
7
+ return target;
8
+ }
@@ -0,0 +1 @@
1
+ export declare function dot(target: Record<string, any>, prefix?: string): Record<string, any>;
@@ -0,0 +1,19 @@
1
+ import { isObject } from "./utils.js";
2
+ export function dot(target, prefix = "") {
3
+ const result = {};
4
+ const handle = (value, currentPrefix) => {
5
+ if (isObject(value)) {
6
+ for (const [key, nested] of Object.entries(value)) {
7
+ const nextPrefix = currentPrefix ? `${currentPrefix}.${key}` : key;
8
+ handle(nested, nextPrefix);
9
+ }
10
+ return;
11
+ }
12
+ result[currentPrefix] = value;
13
+ };
14
+ for (const [key, value] of Object.entries(target)) {
15
+ const nextPrefix = prefix ? `${prefix}.${key}` : key;
16
+ handle(value, nextPrefix);
17
+ }
18
+ return result;
19
+ }
@@ -0,0 +1,2 @@
1
+ import type { Path } from './utils.js';
2
+ export declare function except(target: Record<string, any>, keys: Path | Path[]): Record<string, any>;
@@ -0,0 +1,10 @@
1
+ export function except(target, keys) {
2
+ const exclusion = new Set((Array.isArray(keys) ? keys : [keys]).map((key) => String(key)));
3
+ const result = {};
4
+ for (const [k, v] of Object.entries(target)) {
5
+ if (!exclusion.has(k)) {
6
+ result[k] = v;
7
+ }
8
+ }
9
+ return result;
10
+ }
@@ -0,0 +1,2 @@
1
+ import { type Path } from './utils.js';
2
+ export declare function forget(target: any, paths: Path | Path[]): any;
@@ -0,0 +1,24 @@
1
+ import { toPathArray } from "./utils.js";
2
+ export function forget(target, paths) {
3
+ const list = Array.isArray(paths) ? paths : [paths];
4
+ for (const path of list) {
5
+ const segments = toPathArray(path);
6
+ let current = target;
7
+ for (let i = 0; i < segments.length; i++) {
8
+ const segment = segments[i];
9
+ if (current == null || !(segment in current)) {
10
+ break;
11
+ }
12
+ if (i === segments.length - 1) {
13
+ if (Array.isArray(current)) {
14
+ current.splice(Number(segment), 1);
15
+ } else {
16
+ Reflect.deleteProperty(current, segment);
17
+ }
18
+ } else {
19
+ current = current[segment];
20
+ }
21
+ }
22
+ }
23
+ return target;
24
+ }
@@ -0,0 +1,2 @@
1
+ import { type Path } from './utils.js';
2
+ export declare function get<T = any>(value: any, path: Path, defaultValue?: T): T | undefined;
@@ -0,0 +1,15 @@
1
+ import { isObject, toPathArray } from "./utils.js";
2
+ export function get(value, path, defaultValue) {
3
+ const segments = toPathArray(path);
4
+ let current = value;
5
+ for (const segment of segments) {
6
+ if (isObject(current) || Array.isArray(current)) {
7
+ if (segment in current) {
8
+ current = current[segment];
9
+ continue;
10
+ }
11
+ }
12
+ return defaultValue;
13
+ }
14
+ return current ?? defaultValue;
15
+ }
@@ -0,0 +1,2 @@
1
+ import type { Path } from './utils.js';
2
+ export declare function has(target: any, paths: Path | Path[]): boolean;
@@ -0,0 +1,5 @@
1
+ import { get } from "./get.js";
2
+ export function has(target, paths) {
3
+ const list = Array.isArray(paths) ? paths : [paths];
4
+ return list.every((path) => get(target, path) !== void 0);
5
+ }
@@ -0,0 +1,22 @@
1
+ import { add } from './add.js';
2
+ import { dot } from './dot.js';
3
+ import { except } from './except.js';
4
+ import { forget } from './forget.js';
5
+ import { get } from './get.js';
6
+ import { has } from './has.js';
7
+ import { only } from './only.js';
8
+ import { set } from './set.js';
9
+ import { undot } from './undot.js';
10
+ export interface ObjectHelper {
11
+ add: typeof add;
12
+ dot: typeof dot;
13
+ except: typeof except;
14
+ forget: typeof forget;
15
+ get: typeof get;
16
+ has: typeof has;
17
+ only: typeof only;
18
+ set: typeof set;
19
+ undot: typeof undot;
20
+ }
21
+ export declare function object(): ObjectHelper;
22
+ export { add, dot, except, forget, get, has, only, set, undot, };
@@ -0,0 +1,33 @@
1
+ import { add } from "./add.js";
2
+ import { dot } from "./dot.js";
3
+ import { except } from "./except.js";
4
+ import { forget } from "./forget.js";
5
+ import { get } from "./get.js";
6
+ import { has } from "./has.js";
7
+ import { only } from "./only.js";
8
+ import { set } from "./set.js";
9
+ import { undot } from "./undot.js";
10
+ export function object() {
11
+ return {
12
+ add,
13
+ dot,
14
+ except,
15
+ forget,
16
+ get,
17
+ has,
18
+ only,
19
+ set,
20
+ undot
21
+ };
22
+ }
23
+ export {
24
+ add,
25
+ dot,
26
+ except,
27
+ forget,
28
+ get,
29
+ has,
30
+ only,
31
+ set,
32
+ undot
33
+ };
@@ -0,0 +1,2 @@
1
+ import type { Path } from './utils.js';
2
+ export declare function only(target: Record<string, any>, keys: Path | Path[]): Record<string, any>;
@@ -0,0 +1,12 @@
1
+ import { get } from "./get.js";
2
+ export function only(target, keys) {
3
+ const result = {};
4
+ const list = Array.isArray(keys) ? keys : [keys];
5
+ for (const key of list) {
6
+ const value = get(target, key);
7
+ if (value !== void 0) {
8
+ result[String(key)] = value;
9
+ }
10
+ }
11
+ return result;
12
+ }
@@ -0,0 +1,2 @@
1
+ import { type Path } from './utils.js';
2
+ export declare function set<T extends Record<string, any>>(target: T, path: Path, value: any): T;
@@ -0,0 +1,23 @@
1
+ import { isObject, toPathArray } from "./utils.js";
2
+ export function set(target, path, value) {
3
+ const segments = toPathArray(path);
4
+ if (segments.length === 0) {
5
+ return target;
6
+ }
7
+ let current = target;
8
+ for (let i = 0; i < segments.length; i++) {
9
+ const segment = segments[i];
10
+ const isLast = i === segments.length - 1;
11
+ if (isLast) {
12
+ current[segment] = value;
13
+ } else {
14
+ const next = current[segment];
15
+ if (!isObject(next) && !Array.isArray(next)) {
16
+ const nextSegment = segments[i + 1];
17
+ current[segment] = typeof nextSegment === "number" ? [] : {};
18
+ }
19
+ current = current[segment];
20
+ }
21
+ }
22
+ return target;
23
+ }
@@ -0,0 +1 @@
1
+ export declare function undot(target: Record<string, any>): Record<string, any>;
@@ -0,0 +1,8 @@
1
+ import { set } from "./set.js";
2
+ export function undot(target) {
3
+ const result = {};
4
+ for (const [key, value] of Object.entries(target)) {
5
+ set(result, key, value);
6
+ }
7
+ return result;
8
+ }
@@ -0,0 +1,3 @@
1
+ export type Path = string | number | Array<string | number>;
2
+ export declare function toPathArray(path: Path): Array<string | number>;
3
+ export declare function isObject(value: unknown): value is Record<string, any>;
@@ -0,0 +1,10 @@
1
+ export function toPathArray(path) {
2
+ if (Array.isArray(path)) {
3
+ return path;
4
+ }
5
+ const value = String(path);
6
+ return value.split(".").map((segment) => segment.match(/^\d+$/) ? Number(segment) : segment);
7
+ }
8
+ export function isObject(value) {
9
+ return value !== null && typeof value === "object";
10
+ }
@@ -0,0 +1,6 @@
1
+ export declare function useLocale(locale: string): void;
2
+ export declare function useCurrency(currency: string): void;
3
+ export declare function defaultLocale(): string;
4
+ export declare function defaultCurrency(): string;
5
+ export declare function withLocale<T>(locale: string, callback: () => T | Promise<T>): T | Promise<T>;
6
+ export declare function withCurrency<T>(currency: string, callback: () => T | Promise<T>): T | Promise<T>;
@@ -0,0 +1,50 @@
1
+ let currentLocale = "en";
2
+ let currentCurrency = "USD";
3
+ export function useLocale(locale) {
4
+ currentLocale = locale;
5
+ }
6
+ export function useCurrency(currency) {
7
+ currentCurrency = currency;
8
+ }
9
+ export function defaultLocale() {
10
+ return currentLocale;
11
+ }
12
+ export function defaultCurrency() {
13
+ return currentCurrency;
14
+ }
15
+ export function withLocale(locale, callback) {
16
+ const previousLocale = currentLocale;
17
+ useLocale(locale);
18
+ let result;
19
+ try {
20
+ result = callback();
21
+ } finally {
22
+ if (!(result instanceof Promise)) {
23
+ useLocale(previousLocale);
24
+ }
25
+ }
26
+ if (result instanceof Promise) {
27
+ return result.finally(() => {
28
+ useLocale(previousLocale);
29
+ });
30
+ }
31
+ return result;
32
+ }
33
+ export function withCurrency(currency, callback) {
34
+ const previousCurrency = currentCurrency;
35
+ useCurrency(currency);
36
+ let result;
37
+ try {
38
+ result = callback();
39
+ } finally {
40
+ if (!(result instanceof Promise)) {
41
+ useCurrency(previousCurrency);
42
+ }
43
+ }
44
+ if (result instanceof Promise) {
45
+ return result.finally(() => {
46
+ useCurrency(previousCurrency);
47
+ });
48
+ }
49
+ return result;
50
+ }
@@ -0,0 +1,7 @@
1
+ export declare function length(value: string): number;
2
+ export declare function trim(value: string, mask?: string): string;
3
+ export declare function ltrim(value: string, mask?: string): string;
4
+ export declare function rtrim(value: string, mask?: string): string;
5
+ export declare function start(value: string, prefix: string): string;
6
+ export declare function finish(value: string, suffix: string): string;
7
+ export declare function wrap(value: string, before: string, after?: string): string;
@@ -0,0 +1,42 @@
1
+ export function length(value) {
2
+ return Array.from(value).length;
3
+ }
4
+ export function trim(value, mask) {
5
+ if (!mask) {
6
+ return value.trim();
7
+ }
8
+ const pattern = new RegExp(`^[${escapeMask(mask)}]+|[${escapeMask(mask)}]+$`, "g");
9
+ return value.replace(pattern, "");
10
+ }
11
+ export function ltrim(value, mask) {
12
+ if (!mask) {
13
+ return value.trimStart();
14
+ }
15
+ const pattern = new RegExp(`^[${escapeMask(mask)}]+`, "g");
16
+ return value.replace(pattern, "");
17
+ }
18
+ export function rtrim(value, mask) {
19
+ if (!mask) {
20
+ return value.trimEnd();
21
+ }
22
+ const pattern = new RegExp(`[${escapeMask(mask)}]+$`, "g");
23
+ return value.replace(pattern, "");
24
+ }
25
+ export function start(value, prefix) {
26
+ if (value.startsWith(prefix)) {
27
+ return value;
28
+ }
29
+ return `${prefix}${value}`;
30
+ }
31
+ export function finish(value, suffix) {
32
+ if (value.endsWith(suffix)) {
33
+ return value;
34
+ }
35
+ return `${value}${suffix}`;
36
+ }
37
+ export function wrap(value, before, after = before) {
38
+ return `${before}${value}${after}`;
39
+ }
40
+ function escapeMask(mask) {
41
+ return mask.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
42
+ }
@@ -0,0 +1,6 @@
1
+ export declare function after(value: string, search: string): string;
2
+ export declare function afterLast(value: string, search: string): string;
3
+ export declare function before(value: string, search: string): string;
4
+ export declare function beforeLast(value: string, search: string): string;
5
+ export declare function between(value: string, from: string, to: string): string;
6
+ export declare function betweenFirst(value: string, from: string, to: string): string;
@@ -0,0 +1,42 @@
1
+ export function after(value, search) {
2
+ if (!search) {
3
+ return value;
4
+ }
5
+ const index = value.indexOf(search);
6
+ return index === -1 ? value : value.slice(index + search.length);
7
+ }
8
+ export function afterLast(value, search) {
9
+ if (!search) {
10
+ return value;
11
+ }
12
+ const index = value.lastIndexOf(search);
13
+ return index === -1 ? value : value.slice(index + search.length);
14
+ }
15
+ export function before(value, search) {
16
+ if (!search) {
17
+ return value;
18
+ }
19
+ const index = value.indexOf(search);
20
+ return index === -1 ? value : value.slice(0, index);
21
+ }
22
+ export function beforeLast(value, search) {
23
+ if (!search) {
24
+ return value;
25
+ }
26
+ const index = value.lastIndexOf(search);
27
+ return index === -1 ? value : value.slice(0, index);
28
+ }
29
+ export function between(value, from, to) {
30
+ return before(after(value, from), to);
31
+ }
32
+ export function betweenFirst(value, from, to) {
33
+ const start = value.indexOf(from);
34
+ if (start === -1) {
35
+ return "";
36
+ }
37
+ const end = value.indexOf(to, start + from.length);
38
+ if (end === -1) {
39
+ return "";
40
+ }
41
+ return value.slice(start + from.length, end);
42
+ }
@@ -0,0 +1,9 @@
1
+ export declare function camel(value: string): string;
2
+ export declare function studly(value: string): string;
3
+ export declare function kebab(value: string): string;
4
+ export declare function snake(value: string): string;
5
+ export declare function title(value: string): string;
6
+ export declare function upper(value: string): string;
7
+ export declare function lower(value: string): string;
8
+ export declare function ucfirst(value: string): string;
9
+ export declare function lcfirst(value: string): string;
@@ -0,0 +1,50 @@
1
+ const WORD_SEPARATOR = /[\s_.-]+/;
2
+ function toWords(value) {
3
+ return value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(WORD_SEPARATOR).filter(Boolean);
4
+ }
5
+ export function camel(value) {
6
+ const parts = toWords(value.toLowerCase());
7
+ if (!parts.length) {
8
+ return "";
9
+ }
10
+ return parts.map(
11
+ (part, index) => index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)
12
+ ).join("");
13
+ }
14
+ export function studly(value) {
15
+ const parts = toWords(value.toLowerCase());
16
+ return parts.map(capitalize).join("");
17
+ }
18
+ export function kebab(value) {
19
+ return toWords(value.toLowerCase()).join("-");
20
+ }
21
+ export function snake(value) {
22
+ return toWords(value.toLowerCase()).join("_");
23
+ }
24
+ export function title(value) {
25
+ return toWords(value).map(capitalize).join(" ");
26
+ }
27
+ export function upper(value) {
28
+ return value.toUpperCase();
29
+ }
30
+ export function lower(value) {
31
+ return value.toLowerCase();
32
+ }
33
+ export function ucfirst(value) {
34
+ if (!value) {
35
+ return "";
36
+ }
37
+ return value.charAt(0).toUpperCase() + value.slice(1);
38
+ }
39
+ export function lcfirst(value) {
40
+ if (!value) {
41
+ return "";
42
+ }
43
+ return value.charAt(0).toLowerCase() + value.slice(1);
44
+ }
45
+ function capitalize(value) {
46
+ if (!value) {
47
+ return "";
48
+ }
49
+ return value.charAt(0).toUpperCase() + value.slice(1);
50
+ }