toolbox-x 1.0.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/LICENSE +201 -0
- package/dist/Color-B3mgF9Dh.d.cts +486 -0
- package/dist/Color-D38Xrw65.d.mts +486 -0
- package/dist/Stylog-Df7eq3-j.d.cts +519 -0
- package/dist/Stylog-jvlLcMQq.d.mts +519 -0
- package/dist/array-DvW0zIu6.d.mts +130 -0
- package/dist/array-rUnEVisO.d.cts +130 -0
- package/dist/basics-D_eSv0cu.cjs +132 -0
- package/dist/basics-Dp_aEK81.mjs +115 -0
- package/dist/basics-WEYWlnRO.d.cts +95 -0
- package/dist/basics-uBSfkBEI.d.mts +95 -0
- package/dist/case-BWIt8Ash.mjs +449 -0
- package/dist/case-C-S-b5YP.d.cts +327 -0
- package/dist/case-CS8Ii3A7.cjs +526 -0
- package/dist/case-CybASFPD.d.mts +327 -0
- package/dist/change-case.cjs +32 -0
- package/dist/change-case.d.cts +18 -0
- package/dist/change-case.d.mts +18 -0
- package/dist/change-case.mjs +19 -0
- package/dist/colors.cjs +574 -0
- package/dist/colors.d.cts +355 -0
- package/dist/colors.d.mts +355 -0
- package/dist/colors.mjs +547 -0
- package/dist/constants-2gAw23_7.mjs +144 -0
- package/dist/constants-B34K0QPi.d.cts +21 -0
- package/dist/constants-BIBDKY1u.cjs +924 -0
- package/dist/constants-BWT-810U.cjs +158 -0
- package/dist/constants-BwbHnXlM.mjs +662 -0
- package/dist/constants-BxN9l5el.cjs +74 -0
- package/dist/constants-CLS_bgKD.d.mts +847 -0
- package/dist/constants-D73iFu8g.mjs +171 -0
- package/dist/constants-DAfRxaa8.mjs +62 -0
- package/dist/constants-DQYeCjlx.cjs +207 -0
- package/dist/constants-Deeie-iH.d.mts +21 -0
- package/dist/constants-DpTG9RP6.d.mts +29 -0
- package/dist/constants-DqwnkJ_d.cjs +740 -0
- package/dist/constants-DvRUY_FY.cjs +150 -0
- package/dist/constants-VcRtQu0K.d.cts +29 -0
- package/dist/constants-X5hm1UtB.mjs +912 -0
- package/dist/constants-eNd-iYsV.mjs +134 -0
- package/dist/constants-qm8FafmD.d.cts +847 -0
- package/dist/constants.cjs +415 -0
- package/dist/constants.d.cts +184 -0
- package/dist/constants.d.mts +184 -0
- package/dist/constants.mjs +378 -0
- package/dist/convert-BOCgUv2D.cjs +252 -0
- package/dist/convert-Bn4jFomQ.mjs +169 -0
- package/dist/convert-BrzlG-m_.cjs +475 -0
- package/dist/convert-DhaUoPVU.mjs +368 -0
- package/dist/converter-1P90_RcP.d.mts +402 -0
- package/dist/converter-CmkcAppi.d.cts +402 -0
- package/dist/converter.cjs +780 -0
- package/dist/converter.d.cts +29 -0
- package/dist/converter.d.mts +29 -0
- package/dist/converter.mjs +771 -0
- package/dist/countries-CIpmtEzV.cjs +1469 -0
- package/dist/countries-Cy0xiqS3.mjs +1463 -0
- package/dist/css-colors-Bx947Ng3.d.cts +179 -0
- package/dist/css-colors-CXCDqQbG.cjs +186 -0
- package/dist/css-colors-CXTp1vvy.d.mts +179 -0
- package/dist/css-colors-DfUW3nTR.mjs +180 -0
- package/dist/date.cjs +332 -0
- package/dist/date.d.cts +213 -0
- package/dist/date.d.mts +213 -0
- package/dist/date.mjs +298 -0
- package/dist/dom.cjs +461 -0
- package/dist/dom.d.cts +228 -0
- package/dist/dom.d.mts +228 -0
- package/dist/dom.mjs +429 -0
- package/dist/form-BMFVGUrN.d.mts +118 -0
- package/dist/form-DRFbryvK.d.cts +118 -0
- package/dist/guards-3kaUX66g.mjs +157 -0
- package/dist/guards-C8gkvIHb.cjs +240 -0
- package/dist/guards-DdyU4h4o.mjs +110 -0
- package/dist/guards-Efhp1mNy.cjs +151 -0
- package/dist/guards.cjs +172 -0
- package/dist/guards.d.cts +399 -0
- package/dist/guards.d.mts +399 -0
- package/dist/guards.mjs +75 -0
- package/dist/hash-B6JPEyAz.d.mts +131 -0
- package/dist/hash-NTpeKYB_.d.cts +131 -0
- package/dist/hash.cjs +2126 -0
- package/dist/hash.d.cts +1239 -0
- package/dist/hash.d.mts +1239 -0
- package/dist/hash.mjs +2095 -0
- package/dist/http-status-BAZdtr7-.d.mts +65 -0
- package/dist/http-status-U_3MtoGb.d.cts +65 -0
- package/dist/http-status.cjs +173 -0
- package/dist/http-status.d.cts +142 -0
- package/dist/http-status.d.mts +142 -0
- package/dist/http-status.mjs +171 -0
- package/dist/index.cjs +2551 -0
- package/dist/index.d.cts +1493 -0
- package/dist/index.d.mts +1493 -0
- package/dist/index.mjs +2357 -0
- package/dist/object-B0TV3eHx.d.mts +8052 -0
- package/dist/object-Blq0Amdv.d.cts +8052 -0
- package/dist/objectify-CDs0Fbr1.mjs +417 -0
- package/dist/objectify-DIJ-OBmo.cjs +524 -0
- package/dist/paginator.cjs +245 -0
- package/dist/paginator.d.cts +144 -0
- package/dist/paginator.d.mts +144 -0
- package/dist/paginator.mjs +243 -0
- package/dist/parse-2ubxXZRp.cjs +211 -0
- package/dist/parse-N7g942uy.mjs +164 -0
- package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
- package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
- package/dist/pluralizer.cjs +678 -0
- package/dist/pluralizer.d.cts +152 -0
- package/dist/pluralizer.d.mts +152 -0
- package/dist/pluralizer.mjs +676 -0
- package/dist/primitives-B26uZolQ.cjs +228 -0
- package/dist/primitives-KsFUp3kQ.mjs +144 -0
- package/dist/specials-D48_IZbd.d.mts +108 -0
- package/dist/specials-DzLr1ZgU.cjs +477 -0
- package/dist/specials-LVONlKbQ.d.cts +108 -0
- package/dist/specials-uhDuRg8H.mjs +292 -0
- package/dist/string-CBAbxaG1.d.mts +258 -0
- package/dist/string-CsNsm_65.d.cts +258 -0
- package/dist/stylog.cjs +621 -0
- package/dist/stylog.d.cts +49 -0
- package/dist/stylog.d.mts +49 -0
- package/dist/stylog.mjs +614 -0
- package/dist/timezone-B2OYK6Fh.mjs +5589 -0
- package/dist/timezone-Beh9IGpw.cjs +5625 -0
- package/dist/types/array.cjs +16 -0
- package/dist/types/array.d.cts +18 -0
- package/dist/types/array.d.mts +18 -0
- package/dist/types/array.mjs +17 -0
- package/dist/types/colors.cjs +16 -0
- package/dist/types/colors.d.cts +18 -0
- package/dist/types/colors.d.mts +18 -0
- package/dist/types/colors.mjs +17 -0
- package/dist/types/converter.cjs +16 -0
- package/dist/types/converter.d.cts +18 -0
- package/dist/types/converter.d.mts +18 -0
- package/dist/types/converter.mjs +17 -0
- package/dist/types/form.cjs +16 -0
- package/dist/types/form.d.cts +18 -0
- package/dist/types/form.d.mts +18 -0
- package/dist/types/form.mjs +17 -0
- package/dist/types/hash.cjs +16 -0
- package/dist/types/hash.d.cts +18 -0
- package/dist/types/hash.d.mts +18 -0
- package/dist/types/hash.mjs +17 -0
- package/dist/types/http-status.cjs +16 -0
- package/dist/types/http-status.d.cts +18 -0
- package/dist/types/http-status.d.mts +18 -0
- package/dist/types/http-status.mjs +17 -0
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +18 -0
- package/dist/types/index.d.mts +18 -0
- package/dist/types/index.mjs +17 -0
- package/dist/types/number.cjs +16 -0
- package/dist/types/number.d.cts +18 -0
- package/dist/types/number.d.mts +18 -0
- package/dist/types/number.mjs +17 -0
- package/dist/types/object.cjs +16 -0
- package/dist/types/object.d.cts +18 -0
- package/dist/types/object.d.mts +18 -0
- package/dist/types/object.mjs +17 -0
- package/dist/types/pluralizer.cjs +16 -0
- package/dist/types/pluralizer.d.cts +18 -0
- package/dist/types/pluralizer.d.mts +18 -0
- package/dist/types/pluralizer.mjs +17 -0
- package/dist/types/string.cjs +16 -0
- package/dist/types/string.d.cts +18 -0
- package/dist/types/string.d.mts +18 -0
- package/dist/types/string.mjs +17 -0
- package/dist/types/stylog.cjs +16 -0
- package/dist/types/stylog.d.cts +18 -0
- package/dist/types/stylog.d.mts +18 -0
- package/dist/types/stylog.mjs +17 -0
- package/dist/types/utils.cjs +16 -0
- package/dist/types/utils.d.cts +18 -0
- package/dist/types/utils.d.mts +18 -0
- package/dist/types/utils.mjs +17 -0
- package/dist/types/verbalizer.cjs +16 -0
- package/dist/types/verbalizer.d.cts +30 -0
- package/dist/types/verbalizer.d.mts +30 -0
- package/dist/types/verbalizer.mjs +17 -0
- package/dist/utilities-CLUmdQeV.cjs +140 -0
- package/dist/utilities-m5yFKqLd.mjs +105 -0
- package/dist/utils-ClW9LA6f.mjs +449 -0
- package/dist/utils-DLFRgXUC.cjs +568 -0
- package/dist/verbalizer.cjs +998 -0
- package/dist/verbalizer.d.cts +148 -0
- package/dist/verbalizer.d.mts +148 -0
- package/dist/verbalizer.mjs +996 -0
- package/package.json +249 -0
|
@@ -0,0 +1,243 @@
|
|
|
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 src/utils/Paginator.ts
|
|
18
|
+
/** @class Generates pagination logic, offsets, metadata and other pagination logic(s) for APIs and UIs. */
|
|
19
|
+
var Paginator = class Paginator {
|
|
20
|
+
#totalItems;
|
|
21
|
+
#perPage;
|
|
22
|
+
#currentPage;
|
|
23
|
+
/**
|
|
24
|
+
* * Creates an instance of the Paginator.
|
|
25
|
+
* @param options - The options for pagination.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options) {
|
|
28
|
+
const { totalItems, itemsPerPage = 10, currentPage = 1 } = options ?? {};
|
|
29
|
+
this.#totalItems = Math.max(0, Number(totalItems));
|
|
30
|
+
this.#perPage = Math.max(1, Number(itemsPerPage));
|
|
31
|
+
this.#currentPage = Math.max(1, Number(currentPage));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @instance Returns a new Paginator instance with the given page number.
|
|
35
|
+
* * This method does not modify the current instance.
|
|
36
|
+
* - **N.B.** *If the provided page is out of range, it will be clamped between 1 and the last page.*
|
|
37
|
+
* @param page - The new current page to use.
|
|
38
|
+
* @returns A new Paginator instance with the updated (clamped) page.
|
|
39
|
+
*/
|
|
40
|
+
withPage(page) {
|
|
41
|
+
const safePage = Math.min(Math.max(1, page), this.totalPages());
|
|
42
|
+
return new Paginator({
|
|
43
|
+
totalItems: this.#totalItems,
|
|
44
|
+
itemsPerPage: this.#perPage,
|
|
45
|
+
currentPage: safePage
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @instance Returns a new Paginator instance with the given items per page.
|
|
50
|
+
* - **N.B.** *If the value is less than `1`, it will be clamped to 1.*
|
|
51
|
+
* @param perPage - New items per page value.
|
|
52
|
+
* @returns A new Paginator instance with updated items per page.
|
|
53
|
+
*/
|
|
54
|
+
withPerPage(perPage) {
|
|
55
|
+
const safePerPage = Math.max(1, perPage);
|
|
56
|
+
return new Paginator({
|
|
57
|
+
totalItems: this.#totalItems,
|
|
58
|
+
itemsPerPage: safePerPage,
|
|
59
|
+
currentPage: this.#currentPage
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @instance Returns a new Paginator instance with the given total items.
|
|
64
|
+
* - **N.B.** *If the value is `negative`, it will be clamped to `0`.*
|
|
65
|
+
* @param totalItems - New total items value.
|
|
66
|
+
* @returns A new Paginator instance with updated total items.
|
|
67
|
+
*/
|
|
68
|
+
withTotalItems(totalItems) {
|
|
69
|
+
return new Paginator({
|
|
70
|
+
totalItems: Math.max(0, totalItems),
|
|
71
|
+
itemsPerPage: this.#perPage,
|
|
72
|
+
currentPage: this.#currentPage
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @instance Returns a new Paginator instance with updated pagination options.
|
|
77
|
+
* - **N.B.** *Any value provided will override the existing one, with clamping applied for safety.*
|
|
78
|
+
* @param options - Partial pagination options to override the current instance.
|
|
79
|
+
* @returns A new Paginator instance with merged and clamped options.
|
|
80
|
+
*/
|
|
81
|
+
withOptions(options) {
|
|
82
|
+
const newTotalItems = Math.max(0, options.totalItems ? Number(options.totalItems) : this.#totalItems);
|
|
83
|
+
const newItemsPerPage = Math.max(1, options.itemsPerPage ? Number(options.itemsPerPage) : this.#perPage);
|
|
84
|
+
const totalPages = Math.ceil(newTotalItems / newItemsPerPage);
|
|
85
|
+
return new Paginator({
|
|
86
|
+
totalItems: newTotalItems,
|
|
87
|
+
itemsPerPage: newItemsPerPage,
|
|
88
|
+
currentPage: Math.min(Math.max(1, options.currentPage ? Number(options.currentPage) : this.#currentPage), totalPages)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @instance Calculates the offset (number of items to skip) based on the `current page` and `items per page`.
|
|
93
|
+
* @returns The number of items to skip.
|
|
94
|
+
*/
|
|
95
|
+
offset() {
|
|
96
|
+
return (this.#currentPage - 1) * this.#perPage;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @instance Calculates the offset (number of items to skip) based on the `current page` and `items per page`.
|
|
100
|
+
* @alias of {@link offset}
|
|
101
|
+
* @returns The number of items to skip.
|
|
102
|
+
*/
|
|
103
|
+
getOffset() {
|
|
104
|
+
return this.offset();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @instance Calculates the number of items to skip based on the `current page` and `items per page`.
|
|
108
|
+
* @alias of {@link offset}
|
|
109
|
+
* @returns The number of items to skip.
|
|
110
|
+
*/
|
|
111
|
+
skipCount() {
|
|
112
|
+
return this.offset();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @instance Calculates the total number of pages based on `total items` and `items per page`.
|
|
116
|
+
* @returns The total number of pages.
|
|
117
|
+
*/
|
|
118
|
+
totalPages() {
|
|
119
|
+
return Math.ceil(this.#totalItems / this.#perPage);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* * Returns pagination metadata useful for API responses or UI rendering.
|
|
123
|
+
* @returns An object with pagination metadata.
|
|
124
|
+
*/
|
|
125
|
+
getMeta() {
|
|
126
|
+
const totalPages = this.totalPages();
|
|
127
|
+
return {
|
|
128
|
+
totalItems: this.#totalItems,
|
|
129
|
+
currentPage: this.#currentPage,
|
|
130
|
+
itemsPerPage: this.#perPage,
|
|
131
|
+
totalPages,
|
|
132
|
+
hasPrev: this.hasPrevPage(),
|
|
133
|
+
hasNext: this.hasNextPage(),
|
|
134
|
+
isFirst: this.isFirstPage(),
|
|
135
|
+
isLast: this.isLastPage(),
|
|
136
|
+
offset: this.offset()
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @instance Returns the next page number if it exists.
|
|
141
|
+
* @returns The next page number or null if it's the last page.
|
|
142
|
+
*/
|
|
143
|
+
nextPage() {
|
|
144
|
+
return this.#currentPage < this.totalPages() ? this.#currentPage + 1 : null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @instance Returns the previous page number if it exists.
|
|
148
|
+
* @returns The previous page number or null if it's the first page.
|
|
149
|
+
*/
|
|
150
|
+
prevPage() {
|
|
151
|
+
return this.#currentPage > 1 ? this.#currentPage - 1 : null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @instance Checks if the current page is the first page.
|
|
155
|
+
* @returns Whether the current page is the first page.
|
|
156
|
+
*/
|
|
157
|
+
isFirstPage() {
|
|
158
|
+
return this.#currentPage === 1;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @instance Checks if the current page is the last page.
|
|
162
|
+
* @returns Whether the current page is the last page.
|
|
163
|
+
*/
|
|
164
|
+
isLastPage() {
|
|
165
|
+
return this.#currentPage === this.totalPages();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @instance Checks if a previous page exists.
|
|
169
|
+
* @returns Whether a previous page exists.
|
|
170
|
+
*/
|
|
171
|
+
hasPrevPage() {
|
|
172
|
+
return this.#currentPage > 1;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @instance Checks if a next page exists.
|
|
176
|
+
* @returns Whether a next page exists.
|
|
177
|
+
*/
|
|
178
|
+
hasNextPage() {
|
|
179
|
+
return this.#currentPage < this.totalPages();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @instance Creates an array of page numbers for UI pagination display.
|
|
183
|
+
* @param options Options for customizing the page list.
|
|
184
|
+
* @returns An array of visible page numbers.
|
|
185
|
+
*/
|
|
186
|
+
pageList(options = {}) {
|
|
187
|
+
const total = this.totalPages();
|
|
188
|
+
const edgeCount = Math.max(0, options.edgeCount ?? 1);
|
|
189
|
+
const siblingCount = Math.max(0, options.siblingCount ?? 1);
|
|
190
|
+
const start = Math.max(this.#currentPage - siblingCount, edgeCount + 1);
|
|
191
|
+
const end = Math.min(this.#currentPage + siblingCount, total - edgeCount);
|
|
192
|
+
const _getRange = (from, to) => {
|
|
193
|
+
return from > to ? [] : Array.from({ length: to - from + 1 }, (_, i) => from + i);
|
|
194
|
+
};
|
|
195
|
+
const startPages = _getRange(1, edgeCount);
|
|
196
|
+
const middlePages = _getRange(start, end);
|
|
197
|
+
const endPages = _getRange(total - edgeCount + 1, total);
|
|
198
|
+
const pages = new Set([
|
|
199
|
+
...startPages,
|
|
200
|
+
...middlePages,
|
|
201
|
+
...endPages
|
|
202
|
+
]);
|
|
203
|
+
return Array.from(pages).sort((a, b) => a - b);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @instance Returns the first page number.
|
|
207
|
+
* @returns Always returns 1.
|
|
208
|
+
*/
|
|
209
|
+
firstPage() {
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @instance Returns the last page number based on total items and per page count.
|
|
214
|
+
* @returns The last page number.
|
|
215
|
+
*/
|
|
216
|
+
lastPage() {
|
|
217
|
+
return this.totalPages();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* @instance Checks if a page number is valid within the pagination range.
|
|
221
|
+
* @param page - The page number to validate.
|
|
222
|
+
* @returns Whether the page number is within range.
|
|
223
|
+
*/
|
|
224
|
+
isPageValid(page) {
|
|
225
|
+
const p = Math.floor(page);
|
|
226
|
+
return p >= 1 && p <= this.totalPages();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @static Creates a new Paginator instance from a meta object.
|
|
230
|
+
* @param meta - A pagination metadata object.
|
|
231
|
+
* @returns A new Paginator instance.
|
|
232
|
+
*/
|
|
233
|
+
static fromMeta(meta) {
|
|
234
|
+
return new Paginator({
|
|
235
|
+
totalItems: meta.totalItems,
|
|
236
|
+
itemsPerPage: meta.itemsPerPage,
|
|
237
|
+
currentPage: meta.currentPage
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
export { Paginator };
|
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
const require_primitives = require('./primitives-B26uZolQ.cjs');
|
|
18
|
+
const require_constants = require('./constants-DQYeCjlx.cjs');
|
|
19
|
+
const require_specials = require('./specials-DzLr1ZgU.cjs');
|
|
20
|
+
const require_utilities = require('./utilities-CLUmdQeV.cjs');
|
|
21
|
+
const require_guards = require('./guards-Efhp1mNy.cjs');
|
|
22
|
+
|
|
23
|
+
//#region src/date/helpers.ts
|
|
24
|
+
/** Core formatting logic shared by `formatDate` and `Chronos`, `BanglaCalendar` classes */
|
|
25
|
+
function _formatDateCore(format, dateComponents) {
|
|
26
|
+
const tokenRegex = new RegExp(`^(${require_constants.SORTED_TIME_FORMATS.join("|")})`);
|
|
27
|
+
let result = "";
|
|
28
|
+
let i = 0;
|
|
29
|
+
while (i < format.length) {
|
|
30
|
+
if (format[i] === "[") {
|
|
31
|
+
const end = format.indexOf("]", i);
|
|
32
|
+
if (end !== -1) {
|
|
33
|
+
result += format.slice(i + 1, end);
|
|
34
|
+
i = end + 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const match = tokenRegex.exec(format.slice(i));
|
|
39
|
+
if (match) {
|
|
40
|
+
result += dateComponents[match[0]] ?? match[0];
|
|
41
|
+
i += match[0].length;
|
|
42
|
+
} else {
|
|
43
|
+
result += format[i];
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
/** Core formatting logic shared by `formatDate` and `Chronos` class */
|
|
50
|
+
function _formatDate(format, year, month, day, date, hours, minutes, seconds, milliseconds, offset) {
|
|
51
|
+
const paddedYear = _padZero(year, 4);
|
|
52
|
+
return _formatDateCore(format, {
|
|
53
|
+
YYYY: paddedYear,
|
|
54
|
+
YY: paddedYear.slice(-2),
|
|
55
|
+
yyyy: paddedYear,
|
|
56
|
+
yy: paddedYear.slice(-2),
|
|
57
|
+
M: String(month + 1),
|
|
58
|
+
MM: _padZero(month + 1),
|
|
59
|
+
mmm: require_constants.MONTHS[month].slice(0, 3),
|
|
60
|
+
mmmm: require_constants.MONTHS[month],
|
|
61
|
+
d: require_constants.DAYS[day].slice(0, 2),
|
|
62
|
+
dd: require_constants.DAYS[day].slice(0, 3),
|
|
63
|
+
ddd: require_constants.DAYS[day],
|
|
64
|
+
D: String(date),
|
|
65
|
+
DD: _padZero(date),
|
|
66
|
+
Do: require_utilities.getOrdinal(date),
|
|
67
|
+
H: String(hours),
|
|
68
|
+
HH: _padZero(hours),
|
|
69
|
+
h: String(hours % 12 || 12),
|
|
70
|
+
hh: _padZero(hours % 12 || 12),
|
|
71
|
+
m: String(minutes),
|
|
72
|
+
mm: _padZero(minutes),
|
|
73
|
+
s: String(seconds),
|
|
74
|
+
ss: _padZero(seconds),
|
|
75
|
+
ms: String(milliseconds),
|
|
76
|
+
mss: _padZero(milliseconds, 3),
|
|
77
|
+
a: hours < 12 ? "am" : "pm",
|
|
78
|
+
A: hours < 12 ? "AM" : "PM",
|
|
79
|
+
Z: offset,
|
|
80
|
+
ZZ: offset
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Normalize a time string by adding offset at the end */
|
|
84
|
+
function _normalizeOffset(timeStr) {
|
|
85
|
+
return timeStr.replace(/([+-]\d{2})(?!:)/, "$1:00");
|
|
86
|
+
}
|
|
87
|
+
/** Converts milliseconds to seconds */
|
|
88
|
+
const _toSeconds = (ms) => Math.floor(ms / 1e3);
|
|
89
|
+
/** Converts timestamp seconds to JS `Date` */
|
|
90
|
+
const _secToDate = (sec) => /* @__PURE__ */ new Date(sec * 1e3);
|
|
91
|
+
/** Resolve `timeZoneName` value from `Intl.DateTimeFormat` */
|
|
92
|
+
function _resolveNativeTzName(tzId, type, date) {
|
|
93
|
+
try {
|
|
94
|
+
return new Intl.DateTimeFormat("en", {
|
|
95
|
+
timeZone: tzId,
|
|
96
|
+
timeZoneName: type
|
|
97
|
+
}).formatToParts(date).find((p) => p.type === "timeZoneName")?.value;
|
|
98
|
+
} catch {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Convert `GMT±HH:mm` string to `UTC±HH:mm` format*/
|
|
103
|
+
function _gmtToUtcOffset(gmt) {
|
|
104
|
+
return gmt === "GMT" ? "UTC+00:00" : gmt?.replace(/^GMT/, "UTC");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Convert number to string and pad at the start with zero (`'0'`)
|
|
108
|
+
* @param value Value to convert and pad with
|
|
109
|
+
* @param length Maximum length to pad, default is `2`
|
|
110
|
+
* @returns The padded string
|
|
111
|
+
*/
|
|
112
|
+
function _padZero(value, length = 2) {
|
|
113
|
+
return String(value).padStart(length, "0");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Convert a string, number, or `Date` object to a `Date` object.
|
|
117
|
+
* - If the input is already a `Date`, it is returned as is.
|
|
118
|
+
* - If it's a string, it is parsed into a `Date`.
|
|
119
|
+
* - If it's a number or undefined, it is treated as a timestamp and converted to a `Date`.
|
|
120
|
+
* @param value The date input to convert, which can be a `Date` object, a date string, a timestamp number, or undefined (which defaults to the current date and time).
|
|
121
|
+
* @returns A `Date` object representing the input date.
|
|
122
|
+
*/
|
|
123
|
+
function _dateArgsToDate(value) {
|
|
124
|
+
return require_specials.isDate(value) ? value : new Date(require_primitives.isString(value) ? value.replace(/['"]/g, "") : value ?? Date.now());
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/date/parse.ts
|
|
129
|
+
/**
|
|
130
|
+
* * Parse the given value to milliseconds or optionally to seconds.
|
|
131
|
+
*
|
|
132
|
+
* @param value - The string (with unit) or number (or numeric string) to convert.
|
|
133
|
+
* @param sec - Whether to return the value in seconds. Defaults to `false`.
|
|
134
|
+
* @returns The given value parsed in milliseconds (or seconds if specified).
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* - A numeric value (number or numeric string ({@link Numeric})) is interpreted as seconds count, e.g., `120` or `'120'` will be treated as `'120 seconds'`.
|
|
138
|
+
* - If you use time value with unit ({@link TimeWithUnit}) be sure you provide the time units (days, hours, etc.), otherwise it will return `NaN`, e.g., `'120 unknown'` will return `NaN`.
|
|
139
|
+
*/
|
|
140
|
+
function parseMSec(value, sec = false) {
|
|
141
|
+
if (require_primitives.isNumber(value) || require_specials.isNumericString(value)) return _parse(`${value}s`, sec);
|
|
142
|
+
else if (require_guards.isTimeWithUnit(value)) return _parse(value, sec);
|
|
143
|
+
else return NaN;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* * Parse the given time string and return milliseconds or seconds.
|
|
147
|
+
*
|
|
148
|
+
* @param str - A time string to parse to milliseconds.
|
|
149
|
+
* @param sec - Whether to return the value in seconds. Defaults to `false`.
|
|
150
|
+
* @returns The parsed value in milliseconds (or seconds if specified), or `NaN` if the string can't be parsed.
|
|
151
|
+
*/
|
|
152
|
+
function _parse(str, sec = false) {
|
|
153
|
+
if (!require_primitives.isNonEmptyString(str) || str.length > 100) throw new RangeError(`Value must be a string with length between 1 and 99!`);
|
|
154
|
+
const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(str);
|
|
155
|
+
if (!match?.groups) return NaN;
|
|
156
|
+
const unit = (match.groups.unit ?? "ms").toLowerCase();
|
|
157
|
+
const multiplier = require_constants.MS_MAP[unit];
|
|
158
|
+
if (!multiplier) throw new RangeError(`Unknown unit "${unit}"!`);
|
|
159
|
+
const ms = parseFloat(match.groups.value) * multiplier;
|
|
160
|
+
return sec ? ms / 1e3 : ms;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
Object.defineProperty(exports, '_dateArgsToDate', {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return _dateArgsToDate;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
Object.defineProperty(exports, '_formatDate', {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
get: function () {
|
|
173
|
+
return _formatDate;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(exports, '_gmtToUtcOffset', {
|
|
177
|
+
enumerable: true,
|
|
178
|
+
get: function () {
|
|
179
|
+
return _gmtToUtcOffset;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperty(exports, '_normalizeOffset', {
|
|
183
|
+
enumerable: true,
|
|
184
|
+
get: function () {
|
|
185
|
+
return _normalizeOffset;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
Object.defineProperty(exports, '_resolveNativeTzName', {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () {
|
|
191
|
+
return _resolveNativeTzName;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
Object.defineProperty(exports, '_secToDate', {
|
|
195
|
+
enumerable: true,
|
|
196
|
+
get: function () {
|
|
197
|
+
return _secToDate;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
Object.defineProperty(exports, '_toSeconds', {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
get: function () {
|
|
203
|
+
return _toSeconds;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(exports, 'parseMSec', {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function () {
|
|
209
|
+
return parseMSec;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
import { a as isNonEmptyString, c as isNumber, d as isString } from "./primitives-KsFUp3kQ.mjs";
|
|
18
|
+
import { i as SORTED_TIME_FORMATS, n as MONTHS, r as MS_MAP, t as DAYS } from "./constants-D73iFu8g.mjs";
|
|
19
|
+
import { _ as isDate, d as isNumericString } from "./specials-uhDuRg8H.mjs";
|
|
20
|
+
import { r as getOrdinal } from "./utilities-m5yFKqLd.mjs";
|
|
21
|
+
import { i as isTimeWithUnit } from "./guards-DdyU4h4o.mjs";
|
|
22
|
+
|
|
23
|
+
//#region src/date/helpers.ts
|
|
24
|
+
/** Core formatting logic shared by `formatDate` and `Chronos`, `BanglaCalendar` classes */
|
|
25
|
+
function _formatDateCore(format, dateComponents) {
|
|
26
|
+
const tokenRegex = new RegExp(`^(${SORTED_TIME_FORMATS.join("|")})`);
|
|
27
|
+
let result = "";
|
|
28
|
+
let i = 0;
|
|
29
|
+
while (i < format.length) {
|
|
30
|
+
if (format[i] === "[") {
|
|
31
|
+
const end = format.indexOf("]", i);
|
|
32
|
+
if (end !== -1) {
|
|
33
|
+
result += format.slice(i + 1, end);
|
|
34
|
+
i = end + 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const match = tokenRegex.exec(format.slice(i));
|
|
39
|
+
if (match) {
|
|
40
|
+
result += dateComponents[match[0]] ?? match[0];
|
|
41
|
+
i += match[0].length;
|
|
42
|
+
} else {
|
|
43
|
+
result += format[i];
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
/** Core formatting logic shared by `formatDate` and `Chronos` class */
|
|
50
|
+
function _formatDate(format, year, month, day, date, hours, minutes, seconds, milliseconds, offset) {
|
|
51
|
+
const paddedYear = _padZero(year, 4);
|
|
52
|
+
return _formatDateCore(format, {
|
|
53
|
+
YYYY: paddedYear,
|
|
54
|
+
YY: paddedYear.slice(-2),
|
|
55
|
+
yyyy: paddedYear,
|
|
56
|
+
yy: paddedYear.slice(-2),
|
|
57
|
+
M: String(month + 1),
|
|
58
|
+
MM: _padZero(month + 1),
|
|
59
|
+
mmm: MONTHS[month].slice(0, 3),
|
|
60
|
+
mmmm: MONTHS[month],
|
|
61
|
+
d: DAYS[day].slice(0, 2),
|
|
62
|
+
dd: DAYS[day].slice(0, 3),
|
|
63
|
+
ddd: DAYS[day],
|
|
64
|
+
D: String(date),
|
|
65
|
+
DD: _padZero(date),
|
|
66
|
+
Do: getOrdinal(date),
|
|
67
|
+
H: String(hours),
|
|
68
|
+
HH: _padZero(hours),
|
|
69
|
+
h: String(hours % 12 || 12),
|
|
70
|
+
hh: _padZero(hours % 12 || 12),
|
|
71
|
+
m: String(minutes),
|
|
72
|
+
mm: _padZero(minutes),
|
|
73
|
+
s: String(seconds),
|
|
74
|
+
ss: _padZero(seconds),
|
|
75
|
+
ms: String(milliseconds),
|
|
76
|
+
mss: _padZero(milliseconds, 3),
|
|
77
|
+
a: hours < 12 ? "am" : "pm",
|
|
78
|
+
A: hours < 12 ? "AM" : "PM",
|
|
79
|
+
Z: offset,
|
|
80
|
+
ZZ: offset
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Normalize a time string by adding offset at the end */
|
|
84
|
+
function _normalizeOffset(timeStr) {
|
|
85
|
+
return timeStr.replace(/([+-]\d{2})(?!:)/, "$1:00");
|
|
86
|
+
}
|
|
87
|
+
/** Converts milliseconds to seconds */
|
|
88
|
+
const _toSeconds = (ms) => Math.floor(ms / 1e3);
|
|
89
|
+
/** Converts timestamp seconds to JS `Date` */
|
|
90
|
+
const _secToDate = (sec) => /* @__PURE__ */ new Date(sec * 1e3);
|
|
91
|
+
/** Resolve `timeZoneName` value from `Intl.DateTimeFormat` */
|
|
92
|
+
function _resolveNativeTzName(tzId, type, date) {
|
|
93
|
+
try {
|
|
94
|
+
return new Intl.DateTimeFormat("en", {
|
|
95
|
+
timeZone: tzId,
|
|
96
|
+
timeZoneName: type
|
|
97
|
+
}).formatToParts(date).find((p) => p.type === "timeZoneName")?.value;
|
|
98
|
+
} catch {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Convert `GMT±HH:mm` string to `UTC±HH:mm` format*/
|
|
103
|
+
function _gmtToUtcOffset(gmt) {
|
|
104
|
+
return gmt === "GMT" ? "UTC+00:00" : gmt?.replace(/^GMT/, "UTC");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Convert number to string and pad at the start with zero (`'0'`)
|
|
108
|
+
* @param value Value to convert and pad with
|
|
109
|
+
* @param length Maximum length to pad, default is `2`
|
|
110
|
+
* @returns The padded string
|
|
111
|
+
*/
|
|
112
|
+
function _padZero(value, length = 2) {
|
|
113
|
+
return String(value).padStart(length, "0");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Convert a string, number, or `Date` object to a `Date` object.
|
|
117
|
+
* - If the input is already a `Date`, it is returned as is.
|
|
118
|
+
* - If it's a string, it is parsed into a `Date`.
|
|
119
|
+
* - If it's a number or undefined, it is treated as a timestamp and converted to a `Date`.
|
|
120
|
+
* @param value The date input to convert, which can be a `Date` object, a date string, a timestamp number, or undefined (which defaults to the current date and time).
|
|
121
|
+
* @returns A `Date` object representing the input date.
|
|
122
|
+
*/
|
|
123
|
+
function _dateArgsToDate(value) {
|
|
124
|
+
return isDate(value) ? value : new Date(isString(value) ? value.replace(/['"]/g, "") : value ?? Date.now());
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/date/parse.ts
|
|
129
|
+
/**
|
|
130
|
+
* * Parse the given value to milliseconds or optionally to seconds.
|
|
131
|
+
*
|
|
132
|
+
* @param value - The string (with unit) or number (or numeric string) to convert.
|
|
133
|
+
* @param sec - Whether to return the value in seconds. Defaults to `false`.
|
|
134
|
+
* @returns The given value parsed in milliseconds (or seconds if specified).
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* - A numeric value (number or numeric string ({@link Numeric})) is interpreted as seconds count, e.g., `120` or `'120'` will be treated as `'120 seconds'`.
|
|
138
|
+
* - If you use time value with unit ({@link TimeWithUnit}) be sure you provide the time units (days, hours, etc.), otherwise it will return `NaN`, e.g., `'120 unknown'` will return `NaN`.
|
|
139
|
+
*/
|
|
140
|
+
function parseMSec(value, sec = false) {
|
|
141
|
+
if (isNumber(value) || isNumericString(value)) return _parse(`${value}s`, sec);
|
|
142
|
+
else if (isTimeWithUnit(value)) return _parse(value, sec);
|
|
143
|
+
else return NaN;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* * Parse the given time string and return milliseconds or seconds.
|
|
147
|
+
*
|
|
148
|
+
* @param str - A time string to parse to milliseconds.
|
|
149
|
+
* @param sec - Whether to return the value in seconds. Defaults to `false`.
|
|
150
|
+
* @returns The parsed value in milliseconds (or seconds if specified), or `NaN` if the string can't be parsed.
|
|
151
|
+
*/
|
|
152
|
+
function _parse(str, sec = false) {
|
|
153
|
+
if (!isNonEmptyString(str) || str.length > 100) throw new RangeError(`Value must be a string with length between 1 and 99!`);
|
|
154
|
+
const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(str);
|
|
155
|
+
if (!match?.groups) return NaN;
|
|
156
|
+
const unit = (match.groups.unit ?? "ms").toLowerCase();
|
|
157
|
+
const multiplier = MS_MAP[unit];
|
|
158
|
+
if (!multiplier) throw new RangeError(`Unknown unit "${unit}"!`);
|
|
159
|
+
const ms = parseFloat(match.groups.value) * multiplier;
|
|
160
|
+
return sec ? ms / 1e3 : ms;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
export { _normalizeOffset as a, _toSeconds as c, _gmtToUtcOffset as i, _dateArgsToDate as n, _resolveNativeTzName as o, _formatDate as r, _secToDate as s, parseMSec as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import { it as Numeric } from "./object-B0TV3eHx.mjs";
|
|
18
|
+
|
|
19
|
+
//#region src/types/pluralizer.d.ts
|
|
20
|
+
/** A pair of RegExp and replacement for pluralization rules */
|
|
21
|
+
type PluralizeRule = [RegExp, string];
|
|
22
|
+
/**
|
|
23
|
+
* A map of irregular singular to plural forms.
|
|
24
|
+
* Used for handling exceptions in pluralization.
|
|
25
|
+
*/
|
|
26
|
+
type IrregularMap = Record<string, string>;
|
|
27
|
+
/** * Options for pluralize method. */
|
|
28
|
+
interface PluralizeOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The count to determine singular or plural form. Either number or numeric string.
|
|
31
|
+
* If not provided, bypass the check and pluralize the word anyways.
|
|
32
|
+
*/
|
|
33
|
+
count?: Numeric;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to include the count in the output. Depends on the `count` value.
|
|
36
|
+
* If true, the output will be in the format "2 Categories".
|
|
37
|
+
* If false, it will just return the pluralized word.
|
|
38
|
+
*/
|
|
39
|
+
inclusive?: boolean;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { PluralizeOptions as n, PluralizeRule as r, IrregularMap as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import { it as Numeric } from "./object-Blq0Amdv.cjs";
|
|
18
|
+
|
|
19
|
+
//#region src/types/pluralizer.d.ts
|
|
20
|
+
/** A pair of RegExp and replacement for pluralization rules */
|
|
21
|
+
type PluralizeRule = [RegExp, string];
|
|
22
|
+
/**
|
|
23
|
+
* A map of irregular singular to plural forms.
|
|
24
|
+
* Used for handling exceptions in pluralization.
|
|
25
|
+
*/
|
|
26
|
+
type IrregularMap = Record<string, string>;
|
|
27
|
+
/** * Options for pluralize method. */
|
|
28
|
+
interface PluralizeOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The count to determine singular or plural form. Either number or numeric string.
|
|
31
|
+
* If not provided, bypass the check and pluralize the word anyways.
|
|
32
|
+
*/
|
|
33
|
+
count?: Numeric;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to include the count in the output. Depends on the `count` value.
|
|
36
|
+
* If true, the output will be in the format "2 Categories".
|
|
37
|
+
* If false, it will just return the pluralized word.
|
|
38
|
+
*/
|
|
39
|
+
inclusive?: boolean;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { PluralizeOptions as n, PluralizeRule as r, IrregularMap as t };
|