atomic-fns 1.1.7 → 2.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.
Files changed (216) hide show
  1. package/README.md +405 -60
  2. package/dist/array/index.d.ts +9 -0
  3. package/dist/array/index.js +9 -0
  4. package/dist/array/list.d.ts +99 -0
  5. package/dist/array/list.js +133 -0
  6. package/dist/array/sets.d.ts +130 -0
  7. package/dist/array/sets.js +213 -0
  8. package/dist/async/index.d.ts +6 -0
  9. package/dist/async/index.js +6 -0
  10. package/dist/async/retry.d.ts +38 -0
  11. package/dist/async/retry.js +56 -0
  12. package/dist/async/sleep.d.ts +42 -0
  13. package/dist/async/sleep.js +76 -0
  14. package/dist/collections/bisect.d.ts +103 -0
  15. package/dist/collections/bisect.js +157 -0
  16. package/dist/collections/deque.d.ts +67 -97
  17. package/dist/collections/deque.js +197 -249
  18. package/dist/collections/entries.d.ts +89 -0
  19. package/dist/collections/entries.js +131 -0
  20. package/dist/collections/frozen-set.d.ts +42 -0
  21. package/dist/collections/frozen-set.js +64 -0
  22. package/dist/collections/group.d.ts +141 -0
  23. package/dist/collections/group.js +241 -0
  24. package/dist/collections/heap.d.ts +64 -0
  25. package/dist/collections/heap.js +205 -0
  26. package/dist/collections/index.d.ts +15 -642
  27. package/dist/collections/index.js +14 -716
  28. package/dist/collections/internal/arrayKeys.d.ts +19 -0
  29. package/dist/collections/internal/arrayKeys.js +83 -0
  30. package/dist/collections/internal/invariants.d.ts +4 -0
  31. package/dist/collections/internal/invariants.js +12 -0
  32. package/dist/collections/internal/iterable.d.ts +25 -0
  33. package/dist/collections/internal/iterable.js +62 -0
  34. package/dist/collections/iterate.d.ts +162 -0
  35. package/dist/collections/iterate.js +188 -0
  36. package/dist/collections/lru-cache.d.ts +58 -0
  37. package/dist/collections/lru-cache.js +164 -0
  38. package/dist/collections/order.d.ts +19 -0
  39. package/dist/collections/order.js +38 -0
  40. package/dist/collections/shape.d.ts +32 -0
  41. package/dist/collections/shape.js +86 -0
  42. package/dist/collections/sorted-map.d.ts +171 -0
  43. package/dist/collections/sorted-map.js +845 -0
  44. package/dist/collections/sorted-set.d.ts +103 -0
  45. package/dist/collections/sorted-set.js +147 -0
  46. package/dist/collections/splay-tree.d.ts +82 -0
  47. package/dist/collections/splay-tree.js +354 -0
  48. package/dist/collections/trie.d.ts +58 -0
  49. package/dist/collections/trie.js +196 -0
  50. package/dist/decimal/currency.d.ts +211 -0
  51. package/dist/decimal/currency.js +321 -0
  52. package/dist/decimal/decimal.d.ts +299 -0
  53. package/dist/decimal/decimal.js +660 -0
  54. package/dist/decimal/index.d.ts +11 -145
  55. package/dist/decimal/index.js +10 -374
  56. package/dist/decimal/internal/bits.d.ts +2 -0
  57. package/dist/decimal/internal/bits.js +7 -0
  58. package/dist/decimal/internal/echo.d.ts +4 -0
  59. package/dist/decimal/internal/echo.js +6 -0
  60. package/dist/decimal/internal/isqrt.d.ts +9 -0
  61. package/dist/decimal/internal/isqrt.js +34 -0
  62. package/dist/decimal/internal/locale.d.ts +7 -0
  63. package/dist/decimal/internal/locale.js +24 -0
  64. package/dist/decimal/internal/minor-units.d.ts +2 -0
  65. package/dist/decimal/internal/minor-units.js +33 -0
  66. package/dist/decimal/internal/pow10.d.ts +24 -0
  67. package/dist/decimal/internal/pow10.js +96 -0
  68. package/dist/encoding/base64.d.ts +39 -0
  69. package/dist/encoding/base64.js +53 -0
  70. package/dist/encoding/hex.d.ts +23 -0
  71. package/dist/encoding/hex.js +34 -0
  72. package/dist/encoding/index.d.ts +6 -0
  73. package/dist/encoding/index.js +6 -0
  74. package/dist/function/debounce.d.ts +68 -0
  75. package/dist/function/debounce.js +203 -0
  76. package/dist/function/index.d.ts +6 -0
  77. package/dist/function/index.js +6 -0
  78. package/dist/function/shared.d.ts +2 -0
  79. package/dist/function/shared.js +5 -0
  80. package/dist/function/wrap.d.ts +130 -0
  81. package/dist/function/wrap.js +113 -0
  82. package/dist/hash/digest.d.ts +18 -0
  83. package/dist/hash/digest.js +26 -0
  84. package/dist/hash/hash.d.ts +22 -0
  85. package/dist/hash/hash.js +252 -0
  86. package/dist/hash/hashString.d.ts +13 -0
  87. package/dist/hash/hashString.js +53 -0
  88. package/dist/hash/index.d.ts +8 -0
  89. package/dist/hash/index.js +8 -0
  90. package/dist/hash/stableStringify.d.ts +19 -0
  91. package/dist/hash/stableStringify.js +102 -0
  92. package/dist/id/index.d.ts +7 -0
  93. package/dist/id/index.js +7 -0
  94. package/dist/id/nanoid.d.ts +16 -0
  95. package/dist/id/nanoid.js +65 -0
  96. package/dist/id/uniqueId.d.ts +14 -0
  97. package/dist/id/uniqueId.js +20 -0
  98. package/dist/id/uuid.d.ts +25 -0
  99. package/dist/id/uuid.js +64 -0
  100. package/dist/index.d.ts +15 -8
  101. package/dist/index.js +15 -8
  102. package/dist/internal/bytes.d.ts +11 -0
  103. package/dist/internal/bytes.js +33 -0
  104. package/dist/internal/codec.d.ts +11 -0
  105. package/dist/internal/codec.js +84 -0
  106. package/dist/internal/compare.d.ts +10 -0
  107. package/dist/internal/compare.js +26 -0
  108. package/dist/internal/crypto.d.ts +5 -0
  109. package/dist/internal/crypto.js +11 -0
  110. package/dist/internal/keys.d.ts +12 -0
  111. package/dist/internal/keys.js +23 -0
  112. package/dist/internal/kind.d.ts +44 -0
  113. package/dist/internal/kind.js +139 -0
  114. package/dist/internal/sparse.d.ts +51 -0
  115. package/dist/internal/sparse.js +104 -0
  116. package/dist/internal/text.d.ts +7 -0
  117. package/dist/internal/text.js +15 -0
  118. package/dist/internal/timer.d.ts +10 -0
  119. package/dist/internal/timer.js +17 -0
  120. package/dist/internal/truncate.d.ts +10 -0
  121. package/dist/internal/truncate.js +22 -0
  122. package/dist/internal/walk.d.ts +47 -0
  123. package/dist/internal/walk.js +100 -0
  124. package/dist/is/index.d.ts +8 -0
  125. package/dist/is/index.js +8 -0
  126. package/dist/is/isArrayLike.d.ts +18 -0
  127. package/dist/is/isArrayLike.js +25 -0
  128. package/dist/is/isError.d.ts +13 -0
  129. package/dist/is/isError.js +18 -0
  130. package/dist/is/isNil.d.ts +12 -0
  131. package/dist/is/isNil.js +14 -0
  132. package/dist/is/isPlainObject.d.ts +15 -0
  133. package/dist/is/isPlainObject.js +34 -0
  134. package/dist/number/index.d.ts +7 -0
  135. package/dist/number/index.js +7 -0
  136. package/dist/number/round.d.ts +86 -0
  137. package/dist/number/round.js +130 -0
  138. package/dist/number/stats.d.ts +52 -0
  139. package/dist/number/stats.js +115 -0
  140. package/dist/object/cloneDeep.d.ts +28 -0
  141. package/dist/object/cloneDeep.js +200 -0
  142. package/dist/object/index.d.ts +14 -0
  143. package/dist/object/index.js +13 -0
  144. package/dist/object/isEqual.d.ts +64 -0
  145. package/dist/object/isEqual.js +289 -0
  146. package/dist/object/matches.d.ts +40 -0
  147. package/dist/object/matches.js +284 -0
  148. package/dist/object/merge.d.ts +66 -0
  149. package/dist/object/merge.js +272 -0
  150. package/dist/object/parsePath.d.ts +22 -0
  151. package/dist/object/parsePath.js +111 -0
  152. package/dist/object/path.d.ts +85 -0
  153. package/dist/object/path.js +208 -0
  154. package/dist/object/pick.d.ts +91 -0
  155. package/dist/object/pick.js +180 -0
  156. package/dist/object/reshape.d.ts +73 -0
  157. package/dist/object/reshape.js +144 -0
  158. package/dist/random/index.d.ts +96 -32
  159. package/dist/random/index.js +215 -50
  160. package/dist/string/case.d.ts +71 -0
  161. package/dist/string/case.js +152 -0
  162. package/dist/string/fold.d.ts +35 -0
  163. package/dist/string/fold.js +100 -0
  164. package/dist/string/index.d.ts +6 -187
  165. package/dist/string/index.js +6 -226
  166. package/dist/string/truncate.d.ts +25 -0
  167. package/dist/string/truncate.js +44 -0
  168. package/dist/string/words.d.ts +27 -0
  169. package/dist/string/words.js +241 -0
  170. package/package.json +101 -58
  171. package/dist/collections/BTree.d.ts +0 -229
  172. package/dist/collections/BTree.js +0 -1165
  173. package/dist/collections/Heap.d.ts +0 -69
  174. package/dist/collections/Heap.js +0 -181
  175. package/dist/collections/LRUCache.d.ts +0 -80
  176. package/dist/collections/LRUCache.js +0 -126
  177. package/dist/collections/SortedMap.d.ts +0 -92
  178. package/dist/collections/SortedMap.js +0 -131
  179. package/dist/collections/SortedSet.d.ts +0 -69
  180. package/dist/collections/SortedSet.js +0 -99
  181. package/dist/collections/SortedTree.d.ts +0 -103
  182. package/dist/collections/SortedTree.js +0 -141
  183. package/dist/collections/SplayTree.d.ts +0 -105
  184. package/dist/collections/SplayTree.js +0 -338
  185. package/dist/collections/Trie.d.ts +0 -42
  186. package/dist/collections/Trie.js +0 -104
  187. package/dist/collections/abc.d.ts +0 -152
  188. package/dist/collections/abc.js +0 -39
  189. package/dist/collections/frozenset.d.ts +0 -19
  190. package/dist/collections/frozenset.js +0 -30
  191. package/dist/functools/index.d.ts +0 -130
  192. package/dist/functools/index.js +0 -235
  193. package/dist/globals/index.d.ts +0 -285
  194. package/dist/globals/index.js +0 -463
  195. package/dist/i18n/currency.d.ts +0 -24
  196. package/dist/i18n/currency.js +0 -85
  197. package/dist/i18n/date/index.d.ts +0 -203
  198. package/dist/i18n/date/index.js +0 -531
  199. package/dist/i18n/date/utils.d.ts +0 -65
  200. package/dist/i18n/date/utils.js +0 -290
  201. package/dist/i18n/duration.d.ts +0 -112
  202. package/dist/i18n/duration.js +0 -392
  203. package/dist/i18n/format.d.ts +0 -31
  204. package/dist/i18n/format.js +0 -506
  205. package/dist/i18n/index.d.ts +0 -8
  206. package/dist/i18n/index.js +0 -8
  207. package/dist/itertools/index.d.ts +0 -255
  208. package/dist/itertools/index.js +0 -437
  209. package/dist/math/index.d.ts +0 -96
  210. package/dist/math/index.js +0 -98
  211. package/dist/mod.d.ts +0 -1
  212. package/dist/mod.js +0 -1
  213. package/dist/operators/index.d.ts +0 -152
  214. package/dist/operators/index.js +0 -305
  215. package/dist/types.d.ts +0 -19
  216. package/dist/types.js +0 -1
@@ -1,290 +0,0 @@
1
- /**
2
- * Returns x % n but takes the sign of n instead of x
3
- * @param x
4
- * @param n
5
- * @returns {number}
6
- */
7
- function floorMod(x, n) {
8
- return x - n * Math.floor(x / n);
9
- }
10
- function padStart(input, n = 2) {
11
- const isNeg = input < 0;
12
- let padded;
13
- if (isNeg) {
14
- padded = '-' + ('' + -input).padStart(n, '0');
15
- }
16
- else {
17
- padded = ('' + input).padStart(n, '0');
18
- }
19
- return padded;
20
- }
21
- function parseInteger(str) {
22
- if (str != null && str !== '')
23
- return parseInt(str, 10);
24
- }
25
- function parseFloating(str) {
26
- if (str != null && str !== '')
27
- return parseFloat(str);
28
- }
29
- function parseMilliseconds(str) {
30
- if (str != null && str !== '') {
31
- const f = parseFloat('0.' + str) * 1000;
32
- return Math.floor(f);
33
- }
34
- }
35
- export function minDate(...dates) {
36
- let ans = dates[0];
37
- if (Array.isArray(ans)) {
38
- dates = ans;
39
- ans = ans[0];
40
- }
41
- for (let i = 1; i < dates.length; i++) {
42
- if (dates[i].valueOf() < ans.valueOf()) {
43
- ans = dates[i];
44
- }
45
- }
46
- return ans;
47
- }
48
- export function maxDate(...dates) {
49
- let ans = dates[0];
50
- if (Array.isArray(ans)) {
51
- dates = ans;
52
- ans = ans[0];
53
- }
54
- for (let i = 1; i < dates.length; i++) {
55
- if (dates[i].valueOf() > ans.valueOf()) {
56
- ans = dates[i];
57
- }
58
- }
59
- return ans;
60
- }
61
- /**
62
- * Returns `true` if the year is a leap year, otherwise `false`.
63
- * @param year The date year
64
- * @returns {boolean} `true` if is a leap year
65
- */
66
- export function isLeapYear(year) {
67
- return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
68
- }
69
- /**
70
- * Get the number of days in the given year.
71
- * @param year The date year
72
- * @returns {number} Number of days in year
73
- */
74
- export function daysInYear(year) {
75
- return isLeapYear(year) ? 366 : 365;
76
- }
77
- /**
78
- * Get the number of days in the given date's month and year.
79
- * @param date The specified date
80
- * @returns {number} Number of days in month
81
- */
82
- export function daysInMonth(date) {
83
- const d = new Date(date), year = d.getFullYear(), month = d.getMonth() + 1;
84
- const modMonth = floorMod(month - 1, 12) + 1, modYear = year + (month - modMonth) / 12;
85
- if (modMonth === 2) {
86
- return isLeapYear(modYear) ? 29 : 28;
87
- }
88
- else {
89
- return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1];
90
- }
91
- }
92
- // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
93
- function objToLocalTS(obj) {
94
- let d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond);
95
- // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
96
- if (obj.year < 100 && obj.year >= 0) {
97
- let dt = new Date(d);
98
- dt.setUTCFullYear(dt.getUTCFullYear() - 1900);
99
- d = dt.getTime();
100
- }
101
- return +d;
102
- }
103
- function untruncateYear(year) {
104
- if (year > 99) {
105
- return year;
106
- }
107
- else
108
- return year > 60 ? 1900 + year : 2000 + year;
109
- }
110
- // PARSING
111
- function parseZoneInfo(ts, offsetFormat, locale, timeZone) {
112
- const date = new Date(ts), intlOpts = {
113
- hourCycle: 'h23',
114
- year: 'numeric',
115
- month: '2-digit',
116
- day: '2-digit',
117
- hour: '2-digit',
118
- minute: '2-digit',
119
- timeZone,
120
- timeZoneName: offsetFormat
121
- };
122
- const parsed = new Intl.DateTimeFormat(locale, intlOpts)
123
- .formatToParts(date)
124
- .find((m) => m.type === 'timeZoneName');
125
- return parsed?.value;
126
- }
127
- // signedOffset('-5', '30') -> -330
128
- function signedOffset(offHourStr, offMinuteStr) {
129
- let offHour = parseInt(offHourStr, 10);
130
- // don't || this because we want to preserve -0
131
- if (Number.isNaN(offHour)) {
132
- offHour = 0;
133
- }
134
- const offMin = parseInt(offMinuteStr, 10) || 0, offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin;
135
- return offHour * 60 + offMinSigned;
136
- }
137
- // COERCION
138
- export function asNumber(value) {
139
- const numericValue = Number(value);
140
- if (typeof value === 'boolean' || value === '' || Number.isNaN(numericValue))
141
- throw new Error(`Invalid unit value ${value}`);
142
- return numericValue;
143
- }
144
- function formatOffset(offset, format) {
145
- const hours = Math.trunc(Math.abs(offset / 60)), minutes = Math.trunc(Math.abs(offset % 60)), sign = offset >= 0 ? '+' : '-';
146
- switch (format) {
147
- case 'short':
148
- return `${sign}${padStart(hours, 2)}:${padStart(minutes, 2)}`;
149
- case 'narrow':
150
- return `${sign}${hours}${minutes > 0 ? `:${minutes}` : ''}`;
151
- case 'techie':
152
- return `${sign}${padStart(hours, 2)}${padStart(minutes, 2)}`;
153
- default:
154
- throw new RangeError(`Value format ${format} is out of range for property format`);
155
- }
156
- }
157
- function timeObject(obj) {
158
- const { hour, minute, second, millisecond } = obj;
159
- return { hour, minute, second, millisecond };
160
- }
161
- const ianaRegex = /[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;
162
- const isoDuration = /^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;
163
- function extractISODuration(match) {
164
- const [s, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] = match;
165
- const hasNegativePrefix = s[0] === '-';
166
- const negativeSeconds = secondStr && secondStr[0] === '-';
167
- const maybeNegate = (num, force = false) => num !== undefined && (force || (num && hasNegativePrefix)) ? -num : num;
168
- return [
169
- {
170
- years: maybeNegate(parseFloating(yearStr)),
171
- months: maybeNegate(parseFloating(monthStr)),
172
- weeks: maybeNegate(parseFloating(weekStr)),
173
- days: maybeNegate(parseFloating(dayStr)),
174
- hours: maybeNegate(parseFloating(hourStr)),
175
- minutes: maybeNegate(parseFloating(minuteStr)),
176
- seconds: maybeNegate(parseFloating(secondStr), secondStr === '-0'),
177
- milliseconds: maybeNegate(parseMilliseconds(millisecondsStr), negativeSeconds)
178
- }
179
- ];
180
- }
181
- function parse(s, ...patterns) {
182
- if (s == null) {
183
- return [null, null];
184
- }
185
- for (const [regex, extractor] of patterns) {
186
- const m = regex.exec(s);
187
- if (m) {
188
- return extractor(m);
189
- }
190
- }
191
- return [null, null];
192
- }
193
- export function parseISODuration(s) {
194
- return parse(s, [isoDuration, extractISODuration]);
195
- }
196
- function createUTCDate(...args) {
197
- let date, y = args[0];
198
- // the Date.UTC function remaps years 0-99 to 1900-1999
199
- if (y < 100 && y >= 0) {
200
- args = Array.from(arguments);
201
- // preserve leap years using a full 400 year cycle, then reset
202
- args[0] = y + 400;
203
- date = new Date(Date.UTC.apply(null, args));
204
- if (isFinite(date.getUTCFullYear())) {
205
- date.setUTCFullYear(y);
206
- }
207
- }
208
- else {
209
- date = new Date(Date.UTC.apply(null, arguments));
210
- }
211
- return date;
212
- }
213
- function firstWeekOffset(year, dow, doy) {
214
- var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
215
- fwd = 7 + dow - doy,
216
- // first-week day local weekday -- which local weekday is fwd
217
- fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
218
- return -fwdlw + fwd - 1;
219
- }
220
- // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
221
- function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
222
- var localWeekday = (7 + weekday - dow) % 7, weekOffset = firstWeekOffset(year, dow, doy), dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset, resYear, resDayOfYear;
223
- if (dayOfYear <= 0) {
224
- resYear = year - 1;
225
- resDayOfYear = daysInYear(resYear) + dayOfYear;
226
- }
227
- else if (dayOfYear > daysInYear(year)) {
228
- resYear = year + 1;
229
- resDayOfYear = dayOfYear - daysInYear(year);
230
- }
231
- else {
232
- resYear = year;
233
- resDayOfYear = dayOfYear;
234
- }
235
- return {
236
- year: resYear,
237
- dayOfYear: resDayOfYear
238
- };
239
- }
240
- /**
241
- * Returns the number of weeks in the specified year.
242
- * @param year
243
- * @param firstDayOfWeek
244
- * @param firstDayOfYear
245
- */
246
- export function weeksInYear(year, firstDayOfWeek = 1, firstDayOfYear = 1) {
247
- var weekOffset = firstWeekOffset(year, firstDayOfWeek, firstDayOfYear), weekOffsetNext = firstWeekOffset(year + 1, firstDayOfWeek, firstDayOfYear);
248
- return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
249
- }
250
- /**
251
- * Returns the week of the year for the specified date
252
- * @param year
253
- * @param dayOfYear
254
- * @param firstDayOfWeek
255
- * @param firstDayOfYear
256
- * @returns
257
- */
258
- export function weekOfYear(date, firstDayOfWeek = 1, firstDayOfYear = 1) {
259
- const year = new Date(date).getFullYear();
260
- const doy = dayOfYear(date);
261
- let weekOffset = firstWeekOffset(year, firstDayOfWeek, firstDayOfYear), week = Math.floor((doy - weekOffset - 1) / 7) + 1, resWeek, resYear;
262
- if (week < 1) {
263
- resYear = year - 1;
264
- resWeek = week + weeksInYear(resYear, firstDayOfWeek, firstDayOfYear);
265
- }
266
- else if (week > weeksInYear(year, firstDayOfWeek, firstDayOfYear)) {
267
- resWeek = week - weeksInYear(year, firstDayOfWeek, firstDayOfYear);
268
- resYear = year + 1;
269
- }
270
- else {
271
- resYear = year;
272
- resWeek = week;
273
- }
274
- return {
275
- week: resWeek,
276
- year: resYear
277
- };
278
- }
279
- export function isoWeeksInYear(year) {
280
- return weeksInYear(year, 1, 4);
281
- }
282
- export function dayOfYear(input) {
283
- input = new Date(input);
284
- input.setHours(0);
285
- input.setMinutes(0);
286
- input.setSeconds(0);
287
- input.setMilliseconds(0);
288
- let start = new Date(input.getFullYear(), 0, 1, 0, 0, 0, 0);
289
- return Math.round((+input - start.getTime()) / 864e5) + 1;
290
- }
@@ -1,112 +0,0 @@
1
- export declare type DurationUnit = 'year' | 'years' | 'quarter' | 'quarters' | 'month' | 'months' | 'week' | 'weeks' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds';
2
- export interface TDuration {
3
- years?: number;
4
- months?: number;
5
- weeks?: number;
6
- days?: number;
7
- hours?: number;
8
- minutes?: number;
9
- seconds?: number;
10
- milliseconds?: number;
11
- }
12
- export declare const UNITS_PLURAL: Record<DurationUnit, DurationUnit>;
13
- export declare class Duration {
14
- values: TDuration;
15
- private matrix;
16
- constructor(dur?: number | TDuration | Duration, exact?: boolean);
17
- /** Get the years. */
18
- get years(): number;
19
- /** Get the months. */
20
- get months(): number;
21
- /** Get the weeks. */
22
- get weeks(): number;
23
- /** Get the days. */
24
- get days(): number;
25
- /** Get the hours. */
26
- get hours(): number;
27
- /** et the minutes. */
28
- get minutes(): number;
29
- /** Get the seconds. */
30
- get seconds(): number;
31
- /** Get the milliseconds. */
32
- get milliseconds(): number;
33
- /**
34
- * Get the value of unit.
35
- * @param {string} unit - a unit such as 'minute' or 'day'
36
- * @example Duration.fromObject({years: 2, days: 3}).get('years') // 2
37
- * @example Duration.fromObject({years: 2, days: 3}).get('months') // 0
38
- * @example Duration.fromObject({years: 2, days: 3}).get('days') // 3
39
- * @return {number}
40
- */
41
- get(unit: string): number;
42
- add(duration: TDuration): Duration;
43
- /**
44
- * Make this Duration shorter by the specified amount. Return a newly-constructed Duration.
45
- * @param {Duration|Object|number} duration - The amount to subtract.
46
- * @return {Duration}
47
- */
48
- subtract(duration: Duration | TDuration | number): Duration;
49
- /**
50
- * Return the negative of this Duration.
51
- * @example
52
- ```js
53
- new Duration({ hours: 1, seconds: 30 }).negated().toObject()
54
- // { hours: -1, seconds: -30 }
55
- ```
56
- * @returns {Duration}
57
- */
58
- negated(): Duration;
59
- /**
60
- * Return the absolute values of this Duration.
61
- * @example
62
- ```js
63
- new Duration({ hours: 1, seconds: -30 }).abs().toObject()
64
- // { hours: 1, seconds: 30 }
65
- ```
66
- * @returns {Duration}
67
- */
68
- abs(): Duration;
69
- private shiftToAll;
70
- private shiftTo;
71
- total(unit: DurationUnit): number;
72
- exact(unit?: DurationUnit): number | this;
73
- toObject(): {
74
- years?: number;
75
- months?: number;
76
- weeks?: number;
77
- days?: number;
78
- hours?: number;
79
- minutes?: number;
80
- seconds?: number;
81
- milliseconds?: number;
82
- };
83
- normalize(): Duration;
84
- rescale(): Duration;
85
- /**
86
- * Returns an ISO 8601-compliant string representation of this Duration.
87
- * @see https://en.wikipedia.org/wiki/ISO_8601#Durations
88
- * @example Duration.fromObject({ years: 3, seconds: 45 }).toString() // 'P3YT45S'
89
- * @example Duration.fromObject({ months: 4, seconds: 45 }).toString() // 'P4MT45S'
90
- * @example Duration.fromObject({ months: 5 }).toString() // 'P5M'
91
- * @example Duration.fromObject({ minutes: 5 }).toString() // 'PT5M'
92
- * @example Duration.fromObject({ milliseconds: 6 }).toString() // 'PT0.006S'
93
- * @return {string}
94
- */
95
- toISOString(): string;
96
- toString(): string;
97
- /**
98
- * Create a Duration from an ISO 8601 duration string.
99
- *
100
- * @example
101
- ```js
102
- Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject()
103
- // { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 }
104
- Duration.fromISO('PT23H').toObject()
105
- // { hours: 23 }
106
- Duration.fromISO('P5Y3M').toObject()
107
- // { years: 5, months: 3 }
108
- ```
109
- * @return {Duration}
110
- */
111
- static fromISO(text: string): Duration;
112
- }