chronos-date 2.0.2 → 2.1.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.
- package/README.md +12 -2
- package/dist/constants.d.mts +1 -1
- package/dist/convert-C8LsoKmI-Blf3eLS6.mjs +285 -0
- package/dist/convert-C8LsoKmI-uBhT5hZQ.cjs +387 -0
- package/dist/dist-BPHYJA0t.mjs +70 -0
- package/dist/dist-CdMlZMZa.cjs +75 -0
- package/dist/{greet-DNGvP7nm.mjs → greet-BC86-X9W.mjs} +2 -2
- package/dist/{greet-CMkwXJ7o.cjs → greet-Brz0CVv1.cjs} +8 -8
- package/dist/guards-DTI799nG.mjs +46 -0
- package/dist/guards-dH9JJIso.cjs +51 -0
- package/dist/guards.cjs +14 -16
- package/dist/guards.d.cts +1 -1
- package/dist/guards.d.mts +1 -1
- package/dist/guards.mjs +1 -3
- package/dist/{helpers-Bq7Hczoa.cjs → helpers-BMDeRLjO.cjs} +6 -8
- package/dist/{helpers-C2spzGZ-.mjs → helpers-t49KkxOE.mjs} +2 -4
- package/dist/index.cjs +13 -14
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +4 -5
- package/dist/plugins/banglaPlugin.cjs +16 -33
- package/dist/plugins/banglaPlugin.d.cts +1 -1
- package/dist/plugins/banglaPlugin.d.mts +1 -1
- package/dist/plugins/banglaPlugin.mjs +2 -19
- package/dist/plugins/businessPlugin.cjs +4 -5
- package/dist/plugins/businessPlugin.d.cts +1 -1
- package/dist/plugins/businessPlugin.d.mts +1 -1
- package/dist/plugins/businessPlugin.mjs +1 -2
- package/dist/plugins/dateRangePlugin.cjs +4 -5
- package/dist/plugins/dateRangePlugin.d.cts +1 -1
- package/dist/plugins/dateRangePlugin.d.mts +1 -1
- package/dist/plugins/dateRangePlugin.mjs +1 -2
- package/dist/plugins/dayPartPlugin.cjs +2 -2
- package/dist/plugins/dayPartPlugin.d.cts +1 -1
- package/dist/plugins/dayPartPlugin.d.mts +1 -1
- package/dist/plugins/dayPartPlugin.mjs +1 -1
- package/dist/plugins/durationPlugin.d.cts +1 -1
- package/dist/plugins/durationPlugin.d.mts +1 -1
- package/dist/plugins/fromNowPlugin.cjs +2 -2
- package/dist/plugins/fromNowPlugin.d.cts +1 -1
- package/dist/plugins/fromNowPlugin.d.mts +1 -1
- package/dist/plugins/fromNowPlugin.mjs +1 -1
- package/dist/plugins/greetingPlugin.cjs +1 -1
- package/dist/plugins/greetingPlugin.d.cts +1 -1
- package/dist/plugins/greetingPlugin.d.mts +1 -1
- package/dist/plugins/greetingPlugin.mjs +1 -1
- package/dist/plugins/palindromePlugin.cjs +2 -9
- package/dist/plugins/palindromePlugin.d.cts +1 -1
- package/dist/plugins/palindromePlugin.d.mts +1 -1
- package/dist/plugins/palindromePlugin.mjs +1 -8
- package/dist/plugins/relativeTimePlugin.d.cts +1 -1
- package/dist/plugins/relativeTimePlugin.d.mts +1 -1
- package/dist/plugins/roundPlugin.cjs +8 -8
- package/dist/plugins/roundPlugin.d.cts +1 -1
- package/dist/plugins/roundPlugin.d.mts +1 -1
- package/dist/plugins/roundPlugin.mjs +1 -1
- package/dist/plugins/seasonPlugin.d.cts +1 -1
- package/dist/plugins/seasonPlugin.d.mts +1 -1
- package/dist/plugins/timeZonePlugin.cjs +3 -3
- package/dist/plugins/timeZonePlugin.d.cts +1 -1
- package/dist/plugins/timeZonePlugin.d.mts +1 -1
- package/dist/plugins/timeZonePlugin.mjs +2 -2
- package/dist/plugins/zodiacPlugin.cjs +1 -1
- package/dist/plugins/zodiacPlugin.d.cts +1 -1
- package/dist/plugins/zodiacPlugin.d.mts +1 -1
- package/dist/plugins/zodiacPlugin.mjs +1 -1
- package/dist/{types-Be4ZMpOV.d.mts → types-CiFnGEL8.d.mts} +967 -902
- package/dist/{types-dNpvroNQ.d.cts → types-zhhEJ8N7.d.cts} +966 -901
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/{utilities-C6NiChRE.mjs → utils-DBy7S7hH.mjs} +3 -5
- package/dist/{utilities-CCnKWAsS.cjs → utils-S_aw0TeC.cjs} +8 -10
- package/dist/utils.cjs +33 -34
- package/dist/utils.d.cts +4 -4
- package/dist/utils.d.mts +4 -4
- package/dist/utils.mjs +4 -5
- package/package.json +3 -3
- package/dist/convert-BDQBTK5P.cjs +0 -49
- package/dist/convert-D5Cd0cCg.mjs +0 -38
- package/dist/non-primitives-BqjRwK2B.cjs +0 -68
- package/dist/non-primitives-CbAOB6lb.mjs +0 -38
- package/dist/primitives-BXhrgs9R.mjs +0 -35
- package/dist/primitives-DfO90c3G.cjs +0 -65
- package/dist/utilities-BnHD2hHf.mjs +0 -59
- package/dist/utilities-C_KmjIRK.cjs +0 -88
- /package/dist/{seasons-B_kjFWIX.d.mts → seasons-DYk2jvtn.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -131,9 +131,15 @@ For full documentation, API reference, and interactive playgrounds, visit the [*
|
|
|
131
131
|
|
|
132
132
|
## 🔗 Related Packages
|
|
133
133
|
|
|
134
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
135
|
+
<a target="_blank" href="https://www.npmjs.com/package/toolbox-x">
|
|
136
|
+
<img src="https://img.shields.io/badge/Toolbox--X-toolbox--x-steelblue" alt="toolbox-x" />
|
|
137
|
+
</a>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
134
140
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
135
141
|
<a target="_blank" href="https://www.npmjs.com/package/nhb-toolbox">
|
|
136
|
-
<img src="https://img.shields.io/badge/NHB_Toolbox-nhb--toolbox-
|
|
142
|
+
<img src="https://img.shields.io/badge/NHB_Toolbox-nhb--toolbox-darkred" alt="nhb-toolbox" />
|
|
137
143
|
</a>
|
|
138
144
|
</div>
|
|
139
145
|
|
|
@@ -177,7 +183,11 @@ For full documentation, API reference, and interactive playgrounds, visit the [*
|
|
|
177
183
|
|
|
178
184
|
## License
|
|
179
185
|
|
|
180
|
-
This project is licensed under the [Apache License 2.0](LICENSE)
|
|
186
|
+
This project is licensed under the [Apache License 2.0](LICENSE) with the following additional requirement:
|
|
187
|
+
|
|
188
|
+
**Additional Requirement:**
|
|
189
|
+
|
|
190
|
+
> Any fork, derivative work, or redistribution of this project must include clear attribution to [**Nazmul Hassan**](https://github.com/nazmul-nhb) in both the source code and any publicly available documentation.
|
|
181
191
|
|
|
182
192
|
You are free to use, modify, and distribute this project under the terms of the Apache 2.0 License, provided that appropriate credit is given.
|
|
183
193
|
|
package/dist/constants.d.mts
CHANGED
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { L as VEDIC_ZODIAC_SIGNS, M as MONTHS, R as WESTERN_ZODIAC_SIGNS, _ as TIME_ZONE_LABELS, a as INDIA_IMD_SEASONS, c as JAPAN_SEASONS, d as US_ACADEMIC_SEASONS, f as IANA_TZ_IDS, g as TIME_ZONE_IDS, h as TIME_ZONES_NATIVE, i as ETHIOPIA_SEASONS, l as PHILIPPINES_SEASONS, m as TIME_ZONES, n as BANGLADESH_SEASONS, o as INDIA_TAMIL_SEASONS, p as NATIVE_TZ_IDS, r as DEFAULT_SEASONS, s as INDIA_VEDIC_SEASONS, t as AUSTRALIA_SEASONS, u as SEASON_PRESETS, w as DAYS } from "./seasons-
|
|
17
|
+
import { L as VEDIC_ZODIAC_SIGNS, M as MONTHS, R as WESTERN_ZODIAC_SIGNS, _ as TIME_ZONE_LABELS, a as INDIA_IMD_SEASONS, c as JAPAN_SEASONS, d as US_ACADEMIC_SEASONS, f as IANA_TZ_IDS, g as TIME_ZONE_IDS, h as TIME_ZONES_NATIVE, i as ETHIOPIA_SEASONS, l as PHILIPPINES_SEASONS, m as TIME_ZONES, n as BANGLADESH_SEASONS, o as INDIA_TAMIL_SEASONS, p as NATIVE_TZ_IDS, r as DEFAULT_SEASONS, s as INDIA_VEDIC_SEASONS, t as AUSTRALIA_SEASONS, u as SEASON_PRESETS, w as DAYS } from "./seasons-DYk2jvtn.mjs";
|
|
18
18
|
export { AUSTRALIA_SEASONS, BANGLADESH_SEASONS, ETHIOPIA_SEASONS, IANA_TZ_IDS, INDIA_IMD_SEASONS, INDIA_TAMIL_SEASONS, INDIA_VEDIC_SEASONS, JAPAN_SEASONS, MONTHS, NATIVE_TZ_IDS, PHILIPPINES_SEASONS, SEASON_PRESETS, TIME_ZONES, TIME_ZONES as TZ_ABBREVIATIONS, TIME_ZONES_NATIVE, TIME_ZONE_IDS, TIME_ZONE_LABELS, US_ACADEMIC_SEASONS, VEDIC_ZODIAC_SIGNS, DAYS as WEEK_DAYS, DEFAULT_SEASONS as WESTERN_SEASONS, WESTERN_ZODIAC_SIGNS };
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/primitives-Djsevc69.mjs
|
|
18
|
+
/**
|
|
19
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
20
|
+
*
|
|
21
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
22
|
+
* you may not use this file except in compliance with the License.
|
|
23
|
+
* You may obtain a copy of the License at
|
|
24
|
+
*
|
|
25
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
26
|
+
*
|
|
27
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
28
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
30
|
+
* See the License for the specific language governing permissions and
|
|
31
|
+
* limitations under the License.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* * Type guard to check whether a value is a finite number (excluding `NaN` and `Infinity`).
|
|
35
|
+
* @param value - The value to test.
|
|
36
|
+
* @returns `true` if the value is a finite number; otherwise `false`.
|
|
37
|
+
*/
|
|
38
|
+
function isNumber(value) {
|
|
39
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* * Type guard to check if a value is a string.
|
|
43
|
+
* @param value - The value to check.
|
|
44
|
+
* @returns `true` if the value is a string, otherwise `false`.
|
|
45
|
+
*/
|
|
46
|
+
function isString(value) {
|
|
47
|
+
return typeof value === "string";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* * Type guard to check if a value is a boolean.
|
|
51
|
+
* @param value - The value to check.
|
|
52
|
+
* @returns `true` if the value is a boolean, otherwise `false`.
|
|
53
|
+
*/
|
|
54
|
+
function isBoolean(value) {
|
|
55
|
+
return typeof value === "boolean";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* * Type guard to check if a value is undefined.
|
|
59
|
+
* @param value - The value to check.
|
|
60
|
+
* @returns `true` if the value is undefined, otherwise `false`.
|
|
61
|
+
*/
|
|
62
|
+
function isUndefined(value) {
|
|
63
|
+
return value === void 0;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* * Type guard to check if a value is a non-empty string.
|
|
67
|
+
* @param value - The value to check.
|
|
68
|
+
* @returns `true` if the value is a non-empty string, otherwise `false`.
|
|
69
|
+
*/
|
|
70
|
+
function isNonEmptyString(value) {
|
|
71
|
+
return isString(value) && value?.length > 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/constants-ZyfpysiQ.mjs
|
|
76
|
+
/** * Bangla digits from `০-৯` mapped against `0-9` */
|
|
77
|
+
const BN_DIGITS = /* @__PURE__ */ Object.freeze({
|
|
78
|
+
"০": 0,
|
|
79
|
+
"১": 1,
|
|
80
|
+
"২": 2,
|
|
81
|
+
"৩": 3,
|
|
82
|
+
"৪": 4,
|
|
83
|
+
"৫": 5,
|
|
84
|
+
"৬": 6,
|
|
85
|
+
"৭": 7,
|
|
86
|
+
"৮": 8,
|
|
87
|
+
"৯": 9
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/specials-Cye93-uo.mjs
|
|
92
|
+
/**
|
|
93
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
94
|
+
*
|
|
95
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
96
|
+
* you may not use this file except in compliance with the License.
|
|
97
|
+
* You may obtain a copy of the License at
|
|
98
|
+
*
|
|
99
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
100
|
+
*
|
|
101
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
102
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
103
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
104
|
+
* See the License for the specific language governing permissions and
|
|
105
|
+
* limitations under the License.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* * Type guard to check if a value is an array.
|
|
109
|
+
* @param value - The value to check.
|
|
110
|
+
* @returns `true` if the value is an array, otherwise `false`.
|
|
111
|
+
*/
|
|
112
|
+
function isArray(value) {
|
|
113
|
+
return Array.isArray(value);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* * Type guard to check if a value is an array with length.
|
|
117
|
+
* @param value - The value to check.
|
|
118
|
+
* @returns `true` if the value is an array with length, otherwise `false`.
|
|
119
|
+
*/
|
|
120
|
+
function isValidArray(value) {
|
|
121
|
+
return Array.isArray(value) && value?.length > 0;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* * Type guard to check if a value is an object (excluding null).
|
|
125
|
+
* @param value - The value to check.
|
|
126
|
+
* @returns `true` if the value is an object, otherwise `false`.
|
|
127
|
+
*/
|
|
128
|
+
function isObject(value) {
|
|
129
|
+
return value !== null && typeof value === "object" && !isArray(value);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* * Type guard to check if a value is an object (excluding null) and has keys in it.
|
|
133
|
+
* @param value - The value to check.
|
|
134
|
+
* @returns `true` if the value is an object with valid keys, otherwise `false`.
|
|
135
|
+
*/
|
|
136
|
+
function isNotEmptyObject(value) {
|
|
137
|
+
return isObject(value) && Object.keys(value)?.length > 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* * Type guard to check if a value is an object with specific keys.
|
|
141
|
+
* @param value - The value to check.
|
|
142
|
+
* @param keys - The list of keys the object should contain.
|
|
143
|
+
* @returns `true` if the value is an object with the specified keys, otherwise `false`.
|
|
144
|
+
*/
|
|
145
|
+
function isObjectWithKeys(value, keys) {
|
|
146
|
+
return isObject(value) && keys?.every((key) => key in value);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* * Type guard to check if a value is a function.
|
|
150
|
+
* @param value - The value to check.
|
|
151
|
+
* @returns `true` if the value is a function, otherwise `false`.
|
|
152
|
+
*/
|
|
153
|
+
function isFunction(value) {
|
|
154
|
+
return typeof value === "function";
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* * Type guard to check if a value is a string representing a finite number.
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* - Accepts strings like: `"42"`, `" -5.5 "`, `"0.123"`, `"-0"`, `"1e5"`.
|
|
161
|
+
* - Rejects strings like: `"NaN"`, `"Infinity"`, `"-Infinity"`, `"abc"`, `""`, `"42abc"`.
|
|
162
|
+
*
|
|
163
|
+
* @param value - The value to test.
|
|
164
|
+
* @returns `true` if the value is a string that fully represents a finite number.
|
|
165
|
+
*/
|
|
166
|
+
function isNumericString(value) {
|
|
167
|
+
return isString(value) && value?.trim() !== "" && Number.isFinite(Number(value));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/utilities-B9axOvOX.mjs
|
|
172
|
+
/**
|
|
173
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
174
|
+
*
|
|
175
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
176
|
+
* you may not use this file except in compliance with the License.
|
|
177
|
+
* You may obtain a copy of the License at
|
|
178
|
+
*
|
|
179
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
180
|
+
*
|
|
181
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
182
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
183
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
184
|
+
* See the License for the specific language governing permissions and
|
|
185
|
+
* limitations under the License.
|
|
186
|
+
*/
|
|
187
|
+
/**
|
|
188
|
+
* * Rounds a number to the nearest specified interval.
|
|
189
|
+
* @param value - The number to round.
|
|
190
|
+
* @param interval - The interval to round to. Defaults to `5`.
|
|
191
|
+
* @returns The number rounded to the nearest interval.
|
|
192
|
+
* @example roundToNearest(27, 5) → 25
|
|
193
|
+
*/
|
|
194
|
+
const roundToNearest = (value, interval = 5) => {
|
|
195
|
+
return Math.round(Number(value) / interval) * interval;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* * Returns the ordinal suffix for a given number (e.g., 1 -> 'st', 2 -> 'nd', 3 -> 'rd', 4 -> 'th' etc.).
|
|
199
|
+
* @description The function handles special cases for 11, 12, and 13, which all use 'th' despite the last digit.
|
|
200
|
+
* If the `withNumber` parameter is `true`, the function returns the number along with its ordinal suffix (e.g., "1st").
|
|
201
|
+
* Otherwise, it returns only the ordinal suffix (e.g., "st").
|
|
202
|
+
*
|
|
203
|
+
* @param num - The number or number string to get the ordinal suffix for.
|
|
204
|
+
* @param withNumber - Whether to include the number along with its ordinal suffix (defaults to `true`).
|
|
205
|
+
* @returns The appropriate ordinal suffix, optionally with the number (e.g., '1st' or 'st`, '2nd' or 'nd' and so on.).
|
|
206
|
+
*/
|
|
207
|
+
const getOrdinal = (num, withNumber = true) => {
|
|
208
|
+
const remainder10 = Number(num) % 10;
|
|
209
|
+
const remainder100 = Number(num) % 100;
|
|
210
|
+
let suffix;
|
|
211
|
+
if (remainder10 === 1 && remainder100 !== 11) suffix = "st";
|
|
212
|
+
else if (remainder10 === 2 && remainder100 !== 12) suffix = "nd";
|
|
213
|
+
else if (remainder10 === 3 && remainder100 !== 13) suffix = "rd";
|
|
214
|
+
else suffix = "th";
|
|
215
|
+
return withNumber ? String(num).concat(suffix) : suffix;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* * Normalize a number or numeric string to a number.
|
|
219
|
+
* @description
|
|
220
|
+
* This function checks if the input is a number or a numeric string and converts it to a number.
|
|
221
|
+
* If the input is not a valid number or numeric string, it returns `undefined`.
|
|
222
|
+
* @param num - The number to normalize.
|
|
223
|
+
* @returns The normalized number or `undefined` if the input is not a valid number or numeric string.
|
|
224
|
+
*/
|
|
225
|
+
function normalizeNumber(num) {
|
|
226
|
+
return isNumber(num) ? num : isNumericString(num) ? Number(num) : void 0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/basics-DQe9mP_M.mjs
|
|
231
|
+
/**
|
|
232
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
233
|
+
*
|
|
234
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
235
|
+
* you may not use this file except in compliance with the License.
|
|
236
|
+
* You may obtain a copy of the License at
|
|
237
|
+
*
|
|
238
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
239
|
+
*
|
|
240
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
241
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
242
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
243
|
+
* See the License for the specific language governing permissions and
|
|
244
|
+
* limitations under the License.
|
|
245
|
+
*/
|
|
246
|
+
/**
|
|
247
|
+
* * Trims all the words in a string or an array of strings.
|
|
248
|
+
*
|
|
249
|
+
* @param input String or array of strings.
|
|
250
|
+
* @returns Trimmed string or array of strings.
|
|
251
|
+
*/
|
|
252
|
+
function trimString(input) {
|
|
253
|
+
if (!input) return "";
|
|
254
|
+
if (isNonEmptyString(input)) return input.trim().replace(/\s+/g, " ");
|
|
255
|
+
if (Array.isArray(input)) return input.map((str) => isNonEmptyString(str) ? str.trim().replace(/\s+/g, " ") : str);
|
|
256
|
+
throw new TypeError("Expected string or array of strings!", { cause: "Invalid Input Type" });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region node_modules/.pnpm/toolbox-x@1.0.1-rc.6/node_modules/toolbox-x/dist/convert-C8LsoKmI.mjs
|
|
261
|
+
/**
|
|
262
|
+
* * Reverses a given string.
|
|
263
|
+
* @param input - The string to reverse.
|
|
264
|
+
* @returns The reversed string.
|
|
265
|
+
*/
|
|
266
|
+
const reverseString = (input) => {
|
|
267
|
+
return trimString(input)?.split("")?.reverse()?.join("");
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* * Returns a grammatically correct unit string, optionally prefixed with the number.
|
|
271
|
+
*
|
|
272
|
+
* @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
|
|
273
|
+
*
|
|
274
|
+
* @param count The numeric value to determine singular or plural.
|
|
275
|
+
* @param unit The unit name (e.g., "day", "hour").
|
|
276
|
+
* @param withNumber Whether to prefix the count before the unit. Defaults to `true`.
|
|
277
|
+
* @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`.
|
|
278
|
+
*/
|
|
279
|
+
function formatUnitWithPlural(count, unit, withNumber = true) {
|
|
280
|
+
const pluralized = Math.abs(count) === 1 ? unit : `${unit}s`;
|
|
281
|
+
return withNumber ? `${count} ${pluralized}` : pluralized;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
//#endregion
|
|
285
|
+
export { isUndefined as _, roundToNearest as a, isNumericString as c, isValidArray as d, BN_DIGITS as f, isString as g, isNumber as h, normalizeNumber as i, isObject as l, isNonEmptyString as m, reverseString as n, isFunction as o, isBoolean as p, getOrdinal as r, isNotEmptyObject as s, formatUnitWithPlural as t, isObjectWithKeys as u };
|