nhb-toolbox 4.28.21 → 4.28.30
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/CHANGELOG.md +9 -0
- package/dist/cjs/array/sort.js +65 -8
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/date/plugins/businessPlugin.js +33 -9
- package/dist/cjs/index.js +9 -10
- package/dist/cjs/number/Currency.js +12 -12
- package/dist/cjs/number/constants.js +2 -2
- package/dist/dts/array/sort.d.ts +25 -6
- package/dist/dts/constants.d.ts +1 -1
- package/dist/dts/date/Chronos.d.ts +19 -21
- package/dist/dts/date/plugins/businessPlugin.d.ts +73 -2
- package/dist/dts/index.d.ts +1 -2
- package/dist/dts/number/Currency.d.ts +7 -6
- package/dist/dts/number/constants.d.ts +1 -1
- package/dist/dts/number/types.d.ts +5 -5
- package/dist/dts/types/index.d.ts +26 -13
- package/dist/dts/utils/index.d.ts +3 -3
- package/dist/esm/array/sort.js +61 -5
- package/dist/esm/constants.js +1 -1
- package/dist/esm/date/plugins/businessPlugin.js +33 -9
- package/dist/esm/index.js +1 -2
- package/dist/esm/number/Currency.js +12 -12
- package/dist/esm/number/constants.js +1 -1
- package/package.json +8 -8
- package/dist/cjs/array/utils.js +0 -60
- package/dist/dts/array/utils.d.ts +0 -13
- package/dist/esm/array/utils.js +0 -57
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.28.30] - 2025-12-13
|
|
10
|
+
|
|
11
|
+
- **Updated** *tsdoc* for `Chronos` and *signature* of `Currency` class with generic `CurrencyCode`.
|
|
12
|
+
|
|
13
|
+
## [4.28.24] - 2025-12-11
|
|
14
|
+
|
|
15
|
+
- **Updated** *type names* `VoidFunction` to `VoidFn`. `DelayedFn<T>` is used for both *debounced* and *throttled* functions.
|
|
16
|
+
- **Added** *new* `Chronos` *business plugin methods* `weekendsBetween`, `weekendsInMonth` and `weekendsInYear`.
|
|
17
|
+
|
|
9
18
|
## [4.28.21] - 2025-12-07
|
|
10
19
|
|
|
11
20
|
- **Added** *missing exports* for `getTimeZoneIds` and `getNativeTimeZoneId` *utilities*.
|
package/dist/cjs/array/sort.js
CHANGED
|
@@ -1,14 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.naturalSort = naturalSort;
|
|
3
4
|
exports.sortAnArray = sortAnArray;
|
|
4
5
|
const non_primitives_1 = require("../guards/non-primitives");
|
|
5
6
|
const primitives_1 = require("../guards/primitives");
|
|
6
|
-
|
|
7
|
+
function naturalSort(a, b, options) {
|
|
8
|
+
const { caseInsensitive = true, localeAware = false } = options || {};
|
|
9
|
+
const _createChunks = (str) => {
|
|
10
|
+
const chunks = [];
|
|
11
|
+
let current = '';
|
|
12
|
+
let isNumeric = false;
|
|
13
|
+
for (const char of str) {
|
|
14
|
+
const charIsNum = !Number.isNaN(Number(char));
|
|
15
|
+
if (current?.length === 0) {
|
|
16
|
+
current = char;
|
|
17
|
+
isNumeric = charIsNum;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (charIsNum === isNumeric) {
|
|
21
|
+
current += char;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
chunks?.push(isNumeric ? Number(current) : current);
|
|
25
|
+
current = char;
|
|
26
|
+
isNumeric = charIsNum;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (current?.length > 0) {
|
|
30
|
+
chunks?.push(isNumeric ? Number(current) : current);
|
|
31
|
+
}
|
|
32
|
+
return chunks;
|
|
33
|
+
};
|
|
34
|
+
const aChunks = _createChunks(a);
|
|
35
|
+
const bChunks = _createChunks(b);
|
|
36
|
+
for (let i = 0; i < Math.min(aChunks?.length, bChunks?.length); i++) {
|
|
37
|
+
let aChunk = aChunks[i];
|
|
38
|
+
let bChunk = bChunks[i];
|
|
39
|
+
if (caseInsensitive && typeof aChunk === 'string' && typeof bChunk === 'string') {
|
|
40
|
+
aChunk = aChunk?.toLowerCase();
|
|
41
|
+
bChunk = bChunk?.toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
if (typeof aChunk !== typeof bChunk) {
|
|
44
|
+
return typeof aChunk === 'string' ? 1 : -1;
|
|
45
|
+
}
|
|
46
|
+
if (aChunk !== bChunk) {
|
|
47
|
+
if (typeof aChunk === 'number' && typeof bChunk === 'number') {
|
|
48
|
+
return aChunk - bChunk;
|
|
49
|
+
}
|
|
50
|
+
if (typeof aChunk === 'string' && typeof bChunk === 'string') {
|
|
51
|
+
if (localeAware) {
|
|
52
|
+
const cmp = aChunk.localeCompare(bChunk, undefined, {
|
|
53
|
+
sensitivity: caseInsensitive ? 'accent' : 'variant',
|
|
54
|
+
});
|
|
55
|
+
if (cmp !== 0)
|
|
56
|
+
return cmp;
|
|
57
|
+
}
|
|
58
|
+
return aChunk < bChunk ? -1 : 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return aChunks?.length - bChunks?.length;
|
|
63
|
+
}
|
|
7
64
|
function sortAnArray(array, options) {
|
|
8
65
|
if (!(0, non_primitives_1.isValidArray)(array))
|
|
9
66
|
return array;
|
|
10
67
|
if ((0, non_primitives_1.isArrayOfType)(array, primitives_1.isString)) {
|
|
11
|
-
return [...array].sort((a, b) => options?.sortOrder === 'desc' ?
|
|
68
|
+
return [...array].sort((a, b) => options?.sortOrder === 'desc' ? naturalSort(b, a) : naturalSort(a, b));
|
|
12
69
|
}
|
|
13
70
|
if ((0, non_primitives_1.isArrayOfType)(array, primitives_1.isNumber)) {
|
|
14
71
|
return [...array].sort((a, b) => (options?.sortOrder === 'desc' ? b - a : a - b));
|
|
@@ -28,15 +85,15 @@ function sortAnArray(array, options) {
|
|
|
28
85
|
if (keyA == null || keyB == null) {
|
|
29
86
|
return keyA == null ? 1 : -1;
|
|
30
87
|
}
|
|
31
|
-
if (
|
|
88
|
+
if ((0, primitives_1.isString)(keyA) && (0, primitives_1.isString)(keyB)) {
|
|
32
89
|
return options?.sortOrder === 'desc' ?
|
|
33
|
-
|
|
34
|
-
:
|
|
90
|
+
naturalSort(keyB, keyA)
|
|
91
|
+
: naturalSort(keyA, keyB);
|
|
35
92
|
}
|
|
36
|
-
if (
|
|
93
|
+
if ((0, primitives_1.isNumber)(keyA) && (0, primitives_1.isNumber)(keyB)) {
|
|
37
94
|
return options?.sortOrder === 'desc' ? keyB - keyA : keyA - keyB;
|
|
38
95
|
}
|
|
39
|
-
if (
|
|
96
|
+
if ((0, primitives_1.isBoolean)(keyA) && (0, primitives_1.isBoolean)(keyB)) {
|
|
40
97
|
return options?.sortOrder === 'desc' ?
|
|
41
98
|
Number(keyB) - Number(keyA)
|
|
42
99
|
: Number(keyA) - Number(keyB);
|
|
@@ -44,5 +101,5 @@ function sortAnArray(array, options) {
|
|
|
44
101
|
return 0;
|
|
45
102
|
});
|
|
46
103
|
}
|
|
47
|
-
return array;
|
|
104
|
+
return [...array];
|
|
48
105
|
}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "CSS_COLORS", { enumerable: true, get: function (
|
|
|
34
34
|
var constants_3 = require("./number/constants");
|
|
35
35
|
Object.defineProperty(exports, "CURRENCY_CODES", { enumerable: true, get: function () { return constants_3.CURRENCY_CODES; } });
|
|
36
36
|
Object.defineProperty(exports, "CURRENCY_LOCALES", { enumerable: true, get: function () { return constants_3.CURRENCY_LOCALES; } });
|
|
37
|
-
Object.defineProperty(exports, "FRANKFURTER_CURRENCIES", { enumerable: true, get: function () { return constants_3.
|
|
37
|
+
Object.defineProperty(exports, "FRANKFURTER_CURRENCIES", { enumerable: true, get: function () { return constants_3.FRANKFURTER_CURRENCIES; } });
|
|
38
38
|
Object.defineProperty(exports, "GENERAL_UNITS", { enumerable: true, get: function () { return constants_3.UNITS; } });
|
|
39
39
|
Object.defineProperty(exports, "LOCALE_CODES", { enumerable: true, get: function () { return constants_3.LOCALE_CODES; } });
|
|
40
40
|
var constants_4 = require("./string/constants");
|
|
@@ -15,11 +15,12 @@ const businessPlugin = ($Chronos) => {
|
|
|
15
15
|
mask[d] = false;
|
|
16
16
|
return mask;
|
|
17
17
|
};
|
|
18
|
-
const
|
|
19
|
-
let total = Math.floor(
|
|
20
|
-
let dayIndex =
|
|
21
|
-
for (let i = 0; i <
|
|
22
|
-
|
|
18
|
+
const _countDays = (sWeek, days, mask, step = 1, wd = true) => {
|
|
19
|
+
let total = Math.floor(days / 7) * mask.filter((m) => (wd ? Boolean(m) : !m)).length;
|
|
20
|
+
let dayIndex = ((sWeek % 7) + 7) % 7;
|
|
21
|
+
for (let i = 0; i < days % 7; i++) {
|
|
22
|
+
const isMatch = wd ? Boolean(mask[dayIndex]) : !mask[dayIndex];
|
|
23
|
+
if (isMatch)
|
|
23
24
|
total++;
|
|
24
25
|
dayIndex = (dayIndex + step + 7) % 7;
|
|
25
26
|
}
|
|
@@ -67,26 +68,49 @@ const businessPlugin = ($Chronos) => {
|
|
|
67
68
|
};
|
|
68
69
|
$Chronos.prototype.workdaysBetween = function (to, wDef = 0, wLen = 2) {
|
|
69
70
|
const end = cast(to).startOf('day');
|
|
70
|
-
const start = this.
|
|
71
|
+
const start = this.startOf('day');
|
|
71
72
|
if (start.isSame(end, 'day'))
|
|
72
73
|
return 0;
|
|
73
74
|
const step = start.isBefore(end, 'day') ? 1 : -1;
|
|
74
75
|
const totalDays = Math.abs(end.diff(start, 'day'));
|
|
75
76
|
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
76
77
|
const startWeekday = (start.isoWeekDay + step) % 7;
|
|
77
|
-
return
|
|
78
|
+
return _countDays(startWeekday, totalDays, weekendMask, step);
|
|
79
|
+
};
|
|
80
|
+
$Chronos.prototype.weekendsBetween = function (to, wDef = 0, wLen = 2) {
|
|
81
|
+
const end = cast(to).startOf('day');
|
|
82
|
+
const start = this.startOf('day');
|
|
83
|
+
if (start.isSame(end, 'day'))
|
|
84
|
+
return 0;
|
|
85
|
+
const step = start.isBefore(end, 'day') ? 1 : -1;
|
|
86
|
+
const totalDays = Math.abs(end.diff(start, 'day'));
|
|
87
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
88
|
+
const startWeekday = (start.isoWeekDay + step) % 7;
|
|
89
|
+
return _countDays(startWeekday, totalDays, weekendMask, step, false);
|
|
78
90
|
};
|
|
79
91
|
$Chronos.prototype.workdaysInMonth = function (wDef = 0, wLen = 2) {
|
|
80
92
|
const daysInMonth = this.daysInMonth();
|
|
81
93
|
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
82
94
|
const startWeekday = this.startOf('month').isoWeekDay % 7;
|
|
83
|
-
return
|
|
95
|
+
return _countDays(startWeekday, daysInMonth, weekendMask);
|
|
96
|
+
};
|
|
97
|
+
$Chronos.prototype.weekendsInMonth = function (wDef = 0, wLen = 2) {
|
|
98
|
+
const daysInMonth = this.daysInMonth();
|
|
99
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
100
|
+
const startWeekday = this.startOf('month').isoWeekDay % 7;
|
|
101
|
+
return _countDays(startWeekday, daysInMonth, weekendMask, 1, false);
|
|
84
102
|
};
|
|
85
103
|
$Chronos.prototype.workdaysInYear = function (wDef = 0, wLen = 2) {
|
|
86
104
|
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
87
105
|
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
88
106
|
const startWeekday = this.startOf('year').isoWeekDay % 7;
|
|
89
|
-
return
|
|
107
|
+
return _countDays(startWeekday, daysInYear, weekendMask);
|
|
108
|
+
};
|
|
109
|
+
$Chronos.prototype.weekendsInYear = function (wDef = 0, wLen = 2) {
|
|
110
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
111
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
112
|
+
const startWeekday = this.startOf('year').isoWeekDay % 7;
|
|
113
|
+
return _countDays(startWeekday, daysInYear, weekendMask, 1, false);
|
|
90
114
|
};
|
|
91
115
|
$Chronos.prototype.isBusinessHour = function (options) {
|
|
92
116
|
const _isBusinessHour = () => {
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.convertToDecimal = exports.calculateLCM = exports.calculateLCD = exports
|
|
|
4
4
|
exports.convertRomanToNumeric = exports.convertRomanToInteger = exports.convertRomanToArabic = exports.convertNumberToWordsOrdinal = exports.convertNumberToWords = exports.cardinalWordsToOrdinal = exports.arabicToRoman = exports.isPerfectSquare = exports.isPartOfFibonacciSeries = exports.isPartOfFibonacci = exports.isOddNumber = exports.isOdd = exports.isNumberInvalid = exports.isMultiple = exports.isInvalidNumber = exports.isFibonacci = exports.isEvenNumber = exports.isEven = exports.areNumbersInvalid = exports.areInvalidNumbers = exports.getNthFibonacci = exports.getMemoizedFibonacciSeries = exports.getMemoizedFibonacci = exports.getFibonacciSeriesMemo = exports.getFibonacciSeries = exports.getFibonacciNumbers = exports.getFibonacci = exports.generateFibonacci = exports.fibonacciGenerator = exports.calculatePercentage = exports.UnitConverter = exports.Unit = exports.Currency = exports.sumOfNumbers = exports.sumNumbers = exports.sumDigits = exports.roundToDecimal = exports.roundNumber = exports.reverseNumber = exports.getSumOfNumbers = exports.getRandomNumber = exports.getRandomInt = exports.getFactors = exports.getFactorial = exports.getDivisors = exports.getAverageOfNumbers = exports.getAverage = exports.factorsOf = exports.factorial = exports.convertToFixed = void 0;
|
|
5
5
|
exports.convertHslToHex = exports.convertHslaToRgba = exports.convertHslaToHex8 = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertHex8ToHsla = exports.convertColorCode = exports.getRandomHSL = exports.getRandomColor = exports.generateRandomHSLColor = exports.generateRandomHSL = exports.generateRandomColorInHexRGB = exports.generateRandomColor = exports.getColorForInitial = exports.getNumbersInRange = exports.roundToNearestInterval = exports.roundToNearest = exports.roundNumberToNearestInterval = exports.numberToOrdinal = exports.normalizeNumber = exports.getRandomFloat = exports.getRandomDecimal = exports.getOrdinalNumber = exports.getOrdinal = exports.formatCurrency = exports.convertToOrdinal = exports.convertNumberToOrdinal = exports.convertNumberToCurrency = exports.clampNumber = exports.cardinalToOrdinal = exports.isPrimeNumber = exports.isPrime = exports.getPrimeNumbers = exports.findPrimeNumbers = exports.wordToNumber = exports.wordsToNumber = exports.toRomanNumeral = exports.toRoman = exports.romanToNumeric = exports.romanToInteger = exports.romanToArabic = exports.numericToRoman = exports.numberToWordsOrdinal = exports.numberToWords = exports.numberToRoman = exports.integerToRoman = exports.convertWordToNumber = exports.convertWordsToNumber = exports.convertToRomanNumerals = void 0;
|
|
6
6
|
exports.formatDateTime = exports.formatDate = exports.extractTotalMinutesFromTime = exports.extractTimeStringFromUTC = exports.extractTimeFromUTC = exports.extractMinutesFromUTC = exports.extractHourMinute = exports.convertMinutesToUTCOffset = exports.convertMinutesToTime = exports.convertMinutesToHourMinutes = exports.chronusts = exports.chronusjs = exports.chronus = exports.chronosts = exports.chronosjs = exports.chronos = exports.INTERNALS = exports.Chronus = exports.Chronos = exports.isValidUTCOffset = exports.isValidUTCOffSet = exports.isValidUTC = exports.isValidTimeZoneId = exports.isValidTimeString = exports.isValidTime = exports.isTimeWithUnit = exports.isNativeTimeZoneId = exports.isLeapYear = exports.isDateLike = exports.parseMSec = exports.parseMs = exports.greet = exports.getGreeting = exports.generateGreeting = exports.extractSolidColorValues = exports.extractAlphaColorValues = exports.Colour = exports.Color = exports.isRGBA = exports.isRGB = exports.isHSLA = exports.isHSL = exports.isHex8 = exports.isHex6 = exports.convertRgbToRgba = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertRgbaToHsla = exports.convertRgbaToHex8 = exports.convertHslToRgb = void 0;
|
|
7
|
-
exports.convertIntoFormData = exports.
|
|
7
|
+
exports.convertIntoFormData = exports.splitArrayByProperty = exports.splitArray = exports.rotateArray = exports.removeDuplicatesFromArray = exports.removeDuplicates = exports.moveArrayElement = exports.groupArrayByProperty = exports.getMissingElements = exports.getDuplicatesFromArray = exports.getDuplicates = exports.findMissingElements = exports.extractMissingElements = exports.extractDuplicatesFromArray = exports.extractDuplicates = exports.createOptionsArray = exports.sortAnArray = exports.naturalSortForString = exports.naturalSort = exports.compareSorter = exports.compareNaturally = exports.Finder = exports.totalDeltaByField = exports.sumFieldDifference = exports.sumByField = exports.groupAndSumByField = exports.groupAndAvgByField = exports.groupAndAverageByField = exports.avgByField = exports.averageByField = exports.shuffleArray = exports.isValidEmptyArray = exports.isInvalidOrEmptyArray = exports.getLastArrayElement = exports.flattenArray = exports.filterArrayOfObjects = exports.minutesToUTCOffset = exports.getTotalMinutesFromUTC = exports.getTotalMinutesFromTime = exports.getTotalMinutes = exports.getTimeZoneIds = exports.getTimeZoneDetails = exports.getTimeStringFromUTC = exports.getTimeFromMinutes = exports.getNativeTimeZoneId = exports.getMinutesFromUTC = exports.getHourMinutesFromMinutes = exports.getCurrentTime = exports.getCurrentDateTime = exports.formatUTCOffset = void 0;
|
|
8
8
|
exports.parseQueryStringLiteral = exports.parseQueryString = exports.literalQueryStringToObject = exports.getQueryStringAsObject = exports.getQueryParams = exports.generateQueryParams = exports.formatQueryParams = exports.createQueryParams = exports.removeObjectFields = exports.removeFields = exports.remapObjectFields = exports.remapFields = exports.pickObjectFieldsByCondition = exports.pickObjectFields = exports.pickFieldsByCondition = exports.pickFields = exports.omitObjectFields = exports.omitFields = exports.deleteObjectFields = exports.deleteFields = exports.convertObjectValues = exports.sanitizeData = exports.parseStringifiedObjectValues = exports.parseObjectValues = exports.parseJsonToObject = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = exports.flattenObjectDotNotation = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.extractObjectKeysDeep = exports.extractObjectKeys = exports.extractKeysDeep = exports.extractKeys = exports.countObjectFields = exports.cloneObject = exports.isValidFormData = exports.isOriginFileObj = exports.isFileUpload = exports.isFileOrBlob = exports.isFileList = exports.isFileArray = exports.isCustomFileArray = exports.isCustomFile = exports.serializeForm = exports.parseFormData = exports.createFormData = exports.createControlledFormData = void 0;
|
|
9
9
|
exports.isArrayOfType = exports.isArray = exports.doesReturnPromise = exports.isUndefined = exports.isTruthy = exports.isSymbol = exports.isString = exports.isPrimitive = exports.isPositiveInteger = exports.isNumber = exports.isNull = exports.isNormalPrimitive = exports.isNonEmptyString = exports.isInteger = exports.isFalsy = exports.isBoolean = exports.isBigInt = exports.Paginator = exports.throttleAction = exports.stripJsonEdgeGarbage = exports.stableStringify = exports.parsePrimitivesDeep = exports.parseJsonDeep = exports.parseJSON = exports.joinArrayElements = exports.isDeepEqual = exports.getStaticMethodsCount = exports.getStaticMethodNames = exports.getStaticGetterNames = exports.getInstanceMethodsCount = exports.getInstanceMethodNames = exports.getInstanceGetterNames = exports.getClassDetails = exports.definePrototypeMethod = exports.deepParsePrimitives = exports.debounceAction = exports.countStaticMethods = exports.countInstanceMethods = exports.convertArrayToString = exports.saveToSessionStorage = exports.saveToLocalStorage = exports.removeFromSessionStorage = exports.removeFromLocalStorage = exports.getFromSessionStorage = exports.getFromLocalStorage = exports.toggleFullScreen = exports.smoothScrollTo = exports.copyToClipboard = exports.updateQueryParam = exports.queryStringToObject = void 0;
|
|
10
10
|
exports.isValidURL = exports.isValidEmail = exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBase64 = exports.httpStatus = exports.HttpStatus = exports.isValidSet = exports.isValidObject = exports.isValidMap = exports.isValidJSON = exports.isValidArray = exports.isSet = exports.isReturningPromise = exports.isRegularExpression = exports.isRegExp = exports.isPromise = exports.isObjectWithKeys = exports.isObjectEmpty = exports.isObject = exports.isNotEmptyObject = exports.isMethodDescriptor = exports.isMethod = exports.isMap = exports.isJSONObject = exports.isJSON = exports.isFunction = exports.isError = exports.isEmptyObjectGuard = exports.isEmptyObject = exports.isDate = exports.isArrayWithLength = void 0;
|
|
@@ -273,6 +273,10 @@ Object.defineProperty(exports, "totalDeltaByField", { enumerable: true, get: fun
|
|
|
273
273
|
var Finder_1 = require("./array/Finder");
|
|
274
274
|
Object.defineProperty(exports, "Finder", { enumerable: true, get: function () { return Finder_1.Finder; } });
|
|
275
275
|
var sort_1 = require("./array/sort");
|
|
276
|
+
Object.defineProperty(exports, "compareNaturally", { enumerable: true, get: function () { return sort_1.naturalSort; } });
|
|
277
|
+
Object.defineProperty(exports, "compareSorter", { enumerable: true, get: function () { return sort_1.naturalSort; } });
|
|
278
|
+
Object.defineProperty(exports, "naturalSort", { enumerable: true, get: function () { return sort_1.naturalSort; } });
|
|
279
|
+
Object.defineProperty(exports, "naturalSortForString", { enumerable: true, get: function () { return sort_1.naturalSort; } });
|
|
276
280
|
Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function () { return sort_1.sortAnArray; } });
|
|
277
281
|
var transform_1 = require("./array/transform");
|
|
278
282
|
Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return transform_1.createOptionsArray; } });
|
|
@@ -290,11 +294,6 @@ Object.defineProperty(exports, "removeDuplicatesFromArray", { enumerable: true,
|
|
|
290
294
|
Object.defineProperty(exports, "rotateArray", { enumerable: true, get: function () { return transform_1.rotateArray; } });
|
|
291
295
|
Object.defineProperty(exports, "splitArray", { enumerable: true, get: function () { return transform_1.splitArray; } });
|
|
292
296
|
Object.defineProperty(exports, "splitArrayByProperty", { enumerable: true, get: function () { return transform_1.splitArrayByProperty; } });
|
|
293
|
-
var utils_3 = require("./array/utils");
|
|
294
|
-
Object.defineProperty(exports, "compareNaturally", { enumerable: true, get: function () { return utils_3.naturalSort; } });
|
|
295
|
-
Object.defineProperty(exports, "compareSorter", { enumerable: true, get: function () { return utils_3.naturalSort; } });
|
|
296
|
-
Object.defineProperty(exports, "naturalSort", { enumerable: true, get: function () { return utils_3.naturalSort; } });
|
|
297
|
-
Object.defineProperty(exports, "naturalSortForString", { enumerable: true, get: function () { return utils_3.naturalSort; } });
|
|
298
297
|
var convert_4 = require("./form/convert");
|
|
299
298
|
Object.defineProperty(exports, "convertIntoFormData", { enumerable: true, get: function () { return convert_4.createControlledFormData; } });
|
|
300
299
|
Object.defineProperty(exports, "createControlledFormData", { enumerable: true, get: function () { return convert_4.createControlledFormData; } });
|
|
@@ -356,10 +355,10 @@ Object.defineProperty(exports, "parseQueryString", { enumerable: true, get: func
|
|
|
356
355
|
Object.defineProperty(exports, "parseQueryStringLiteral", { enumerable: true, get: function () { return query_1.parseQueryStringLiteral; } });
|
|
357
356
|
Object.defineProperty(exports, "queryStringToObject", { enumerable: true, get: function () { return query_1.parseQueryString; } });
|
|
358
357
|
Object.defineProperty(exports, "updateQueryParam", { enumerable: true, get: function () { return query_1.updateQueryParam; } });
|
|
359
|
-
var
|
|
360
|
-
Object.defineProperty(exports, "copyToClipboard", { enumerable: true, get: function () { return
|
|
361
|
-
Object.defineProperty(exports, "smoothScrollTo", { enumerable: true, get: function () { return
|
|
362
|
-
Object.defineProperty(exports, "toggleFullScreen", { enumerable: true, get: function () { return
|
|
358
|
+
var utils_3 = require("./dom/utils");
|
|
359
|
+
Object.defineProperty(exports, "copyToClipboard", { enumerable: true, get: function () { return utils_3.copyToClipboard; } });
|
|
360
|
+
Object.defineProperty(exports, "smoothScrollTo", { enumerable: true, get: function () { return utils_3.smoothScrollTo; } });
|
|
361
|
+
Object.defineProperty(exports, "toggleFullScreen", { enumerable: true, get: function () { return utils_3.toggleFullScreen; } });
|
|
363
362
|
var storage_1 = require("./dom/storage");
|
|
364
363
|
Object.defineProperty(exports, "getFromLocalStorage", { enumerable: true, get: function () { return storage_1.getFromLocalStorage; } });
|
|
365
364
|
Object.defineProperty(exports, "getFromSessionStorage", { enumerable: true, get: function () { return storage_1.getFromSessionStorage; } });
|
|
@@ -11,37 +11,37 @@ class Currency {
|
|
|
11
11
|
this.#code = code;
|
|
12
12
|
this.currency = this.format('en-US');
|
|
13
13
|
}
|
|
14
|
-
static #
|
|
14
|
+
static #RATE_CACHE = new Map();
|
|
15
15
|
static clearRateCache() {
|
|
16
|
-
Currency.#
|
|
16
|
+
Currency.#RATE_CACHE.clear();
|
|
17
17
|
}
|
|
18
18
|
format(locale, code) {
|
|
19
19
|
return (0, utilities_1.formatCurrency)(this.#amount, code ?? this.#code, locale);
|
|
20
20
|
}
|
|
21
21
|
async convert(to, options) {
|
|
22
22
|
const key = `${this.#code}->${to}`;
|
|
23
|
-
if (!options?.forceRefresh && Currency.#
|
|
24
|
-
const cachedRate = Currency.#
|
|
23
|
+
if (!options?.forceRefresh && Currency.#RATE_CACHE.has(key)) {
|
|
24
|
+
const cachedRate = Currency.#RATE_CACHE.get(key);
|
|
25
25
|
return new Currency(this.#amount * cachedRate, to);
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
28
|
const rate = await this.#fetchFromFrankfurter(to);
|
|
29
|
-
Currency.#
|
|
29
|
+
Currency.#RATE_CACHE.set(key, rate);
|
|
30
30
|
return new Currency(this.#amount * rate, to);
|
|
31
31
|
}
|
|
32
32
|
catch (error) {
|
|
33
33
|
if (options?.fallbackRate != null) {
|
|
34
|
-
console.warn(`Currency conversion failed (${this.#code} → ${to}): ${error
|
|
34
|
+
console.warn(`Currency conversion failed (${this.#code} → ${to}): ${error?.message}. Using fallback rate...`);
|
|
35
35
|
return new Currency(this.#amount * options.fallbackRate, to);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
throw new Error(`Currency conversion failed (${this.#code} → ${to}): ${error
|
|
38
|
+
throw new Error(`Currency conversion failed (${this.#code} → ${to}): ${error?.message}`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
convertSync(to, rate) {
|
|
43
43
|
const key = `${this.#code}->${to}`;
|
|
44
|
-
const cachedRate = Currency.#
|
|
44
|
+
const cachedRate = Currency.#RATE_CACHE.get(key);
|
|
45
45
|
if (cachedRate) {
|
|
46
46
|
return new Currency(this.#amount * cachedRate, to);
|
|
47
47
|
}
|
|
@@ -53,7 +53,7 @@ class Currency {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
async #fetchFromFrankfurter(to) {
|
|
56
|
-
const url = `https://api.frankfurter.app/latest?amount
|
|
56
|
+
const url = `https://api.frankfurter.app/latest?amount=1&from=${this.#code}`;
|
|
57
57
|
try {
|
|
58
58
|
const res = await fetch(url, { redirect: 'error' });
|
|
59
59
|
if (!res.ok) {
|
|
@@ -61,12 +61,12 @@ class Currency {
|
|
|
61
61
|
}
|
|
62
62
|
const data = await res.json();
|
|
63
63
|
if (!data.rates?.[to]) {
|
|
64
|
-
throw new Error(`Currency "${to}"
|
|
64
|
+
throw new Error(`Currency "${to}" is not found in FrankFurter Database!`);
|
|
65
65
|
}
|
|
66
|
-
return data.rates[to]
|
|
66
|
+
return data.rates[to];
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
69
|
-
throw new Error(error
|
|
69
|
+
throw new Error(error?.message || `Failed to fetch data from FrankFurter API`);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PREFIX_MULTIPLIERS = exports.UNITS = exports.
|
|
3
|
+
exports.PREFIX_MULTIPLIERS = exports.UNITS = exports.FRANKFURTER_CURRENCIES = exports.CURRENCY_LOCALES = exports.LOCALE_CODES = exports.CURRENCY_CODES = exports.ORDINAL_TO_CARDINAL = exports.ORDINAL_UNDER_TEEN = exports.THOUSANDS = exports.TENS = exports.TEENS = exports.ONES = void 0;
|
|
4
4
|
exports.ONES = /* @__PURE__ */ Object.freeze([
|
|
5
5
|
'',
|
|
6
6
|
'one',
|
|
@@ -541,7 +541,7 @@ exports.CURRENCY_LOCALES = /* @__PURE__ */ Object.freeze({
|
|
|
541
541
|
ZMW: 'en-ZM',
|
|
542
542
|
ZWL: 'en-ZW',
|
|
543
543
|
});
|
|
544
|
-
exports.
|
|
544
|
+
exports.FRANKFURTER_CURRENCIES = /* @__PURE__ */ Object.freeze([
|
|
545
545
|
'AUD',
|
|
546
546
|
'BGN',
|
|
547
547
|
'BRL',
|
package/dist/dts/array/sort.d.ts
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
import type { GenericObject } from '../object/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BasicPrimitive } from '../types/index';
|
|
3
|
+
import type { OrderOption, SortByOption, SortNature } from './types';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Compare two strings using natural sorting (e.g., `"file2"` < `"file10"`).
|
|
6
|
+
* - Optionally supports case-insensitive and locale-aware string chunk comparisons.
|
|
5
7
|
*
|
|
6
|
-
* -
|
|
8
|
+
* @param a - The first string to compare.
|
|
9
|
+
* @param b - The second string to compare.
|
|
10
|
+
* @param options - Optional settings to configure comparison behavior.
|
|
11
|
+
* @returns A negative number if `a` comes before `b`, a positive number if `a` comes after `b`, or 0 if equal.
|
|
12
|
+
*/
|
|
13
|
+
export declare function naturalSort(a: string, b: string, options?: SortNature): number;
|
|
14
|
+
/**
|
|
15
|
+
* * Sorts an array of objects based on the provided options.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* - Sorts array by the specified field in the options `sortByField`.
|
|
19
|
+
* - Uses {@link naturalSort} for sorting string values.
|
|
7
20
|
*
|
|
8
21
|
* @param array - The array of objects to sort.
|
|
9
|
-
* @param options - Sorting options.
|
|
22
|
+
* @param options - Sorting options for objects.
|
|
10
23
|
* @returns The sorted array.
|
|
11
24
|
*/
|
|
12
25
|
export declare function sortAnArray<T extends GenericObject>(array: T[], options: SortByOption<T>): T[];
|
|
13
26
|
/**
|
|
14
|
-
* * Sorts an array of `strings`, `numbers` or `boolean
|
|
27
|
+
* * Sorts an array of `strings`, `numbers` or `boolean` based on the provided options.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - If the array contains strings, it sorts them alphabetically.
|
|
31
|
+
* - If the array contains numbers, it sorts them numerically.
|
|
32
|
+
* - If the array contains booleans, it sorts them by their boolean value.
|
|
33
|
+
* - Uses {@link naturalSort} for sorting string values.
|
|
15
34
|
*
|
|
16
35
|
* @param array - The array of `strings`, `numbers` or `boolean` to sort.
|
|
17
36
|
* @param options - Sorting options.
|
|
18
37
|
* @returns The sorted array.
|
|
19
38
|
*/
|
|
20
|
-
export declare function sortAnArray<T extends
|
|
39
|
+
export declare function sortAnArray<T extends BasicPrimitive>(array: T[], options?: OrderOption): T[];
|
package/dist/dts/constants.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { IANA_TZ_IDS, NATIVE_TZ_IDS, TIME_ZONE_IDS, TIME_ZONE_LABELS, TIME_ZONES
|
|
|
3
3
|
export { AUSTRALIA_SEASONS, BANGLADESH_SEASONS, ETHIOPIA_SEASONS, INDIA_IMD_SEASONS, INDIA_TAMIL_SEASONS, INDIA_VEDIC_SEASONS, JAPAN_SEASONS, PHILIPPINES_SEASONS, SEASON_PRESETS, US_ACADEMIC_SEASONS, DEFAULT_SEASONS as WESTERN_SEASONS, } from './date/seasons';
|
|
4
4
|
export { ALPHABET_COLOR_PALETTE, NUMBER_COLOR_PALETTE } from './colors/constants';
|
|
5
5
|
export { CSS_COLORS } from './colors/css-colors';
|
|
6
|
-
export { CURRENCY_CODES, CURRENCY_LOCALES,
|
|
6
|
+
export { CURRENCY_CODES, CURRENCY_LOCALES, FRANKFURTER_CURRENCIES, UNITS as GENERAL_UNITS, LOCALE_CODES, } from './number/constants';
|
|
7
7
|
export { LOWERCASE as LOWERCASED_WORDS } from './string/constants';
|
|
8
8
|
export { UNITS as CATEGORIZED_UNITS } from './converter/constants';
|
|
9
9
|
export { COUNTRIES } from './object/countries';
|
|
@@ -3,16 +3,17 @@ import type { LooseLiteral, TupleOf } from '../utils/types';
|
|
|
3
3
|
import { INTERNALS } from './constants';
|
|
4
4
|
import type { $NativeTzNameOrId, $TimeZoneIdentifier, $UTCOffset, ChronosInput, ChronosInternals, ChronosMethods, ChronosObject, ChronosPlugin, ChronosWithOptions, DateRangeOptions, DateTimeFormatOptions, FormatOptions, LocalesArguments, Milliseconds, MonthName, Quarter, RangeWithDates, RelativeDateRange, RelativeRangeOptions, StrictFormat, TimeParts, TimeUnit, TimeUnitValue, TimeZone, TimeZoneId, TimeZoneIdNative, TimeZoneName, UTCOffset, WeekDay } from './types';
|
|
5
5
|
/**
|
|
6
|
-
* * Creates a new immutable
|
|
6
|
+
* * Creates a new immutable `Chronos` instance.
|
|
7
7
|
*
|
|
8
|
-
* **Note**:
|
|
9
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
8
|
+
* **Note**:
|
|
9
|
+
* - *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
10
10
|
*
|
|
11
11
|
* @param value - A date value (`number`, `string`, `Date`, or `Chronos` object).
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* - If a string is provided, it should be in a format that can be parsed by the {@link Date} constructor.
|
|
13
15
|
* - If a number is provided, it should be a timestamp (milliseconds since the Unix epoch).
|
|
14
|
-
* - If a `Date` object is provided, it will be
|
|
15
|
-
* - If a `Chronos` object is provided, it will be converted to a `Date` object.
|
|
16
|
+
* - If a `Date` or `Chronos` object is provided, it will be handled internally to parse the date value.
|
|
16
17
|
*
|
|
17
18
|
* **It also accepts number values as following:**
|
|
18
19
|
* - **`year, month, date, hours, minutes, seconds, milliseconds`**: Individual components of a date-time to construct a `Chronos` instance.
|
|
@@ -68,7 +69,7 @@ export declare class Chronos {
|
|
|
68
69
|
/** Tracker to identify the instance created by {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos/conversion#timezone timeZone} method */
|
|
69
70
|
protected $tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset;
|
|
70
71
|
/**
|
|
71
|
-
* * Creates a new immutable
|
|
72
|
+
* * Creates a new immutable `Chronos` instance.
|
|
72
73
|
*
|
|
73
74
|
* Accepts no arguments (defaults to now).
|
|
74
75
|
*
|
|
@@ -76,7 +77,7 @@ export declare class Chronos {
|
|
|
76
77
|
*/
|
|
77
78
|
constructor();
|
|
78
79
|
/**
|
|
79
|
-
* * Creates a new immutable
|
|
80
|
+
* * Creates a new immutable `Chronos` instance.
|
|
80
81
|
*
|
|
81
82
|
* @param value - A date value in `number`, it should be a timestamp (milliseconds since the Unix epoch).
|
|
82
83
|
*
|
|
@@ -84,26 +85,25 @@ export declare class Chronos {
|
|
|
84
85
|
*/
|
|
85
86
|
constructor(value: number);
|
|
86
87
|
/**
|
|
87
|
-
* * Creates a new immutable
|
|
88
|
+
* * Creates a new immutable `Chronos` instance.
|
|
88
89
|
*
|
|
89
|
-
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
90
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
90
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
91
91
|
*
|
|
92
|
-
* @param value - A date value in `string`, it should be in a format that can be parsed by the
|
|
92
|
+
* @param value - A date value in `string`, it should be in a format that can be parsed by the {@link Date} constructor.
|
|
93
93
|
*
|
|
94
94
|
* @returns Instance of `Chronos` with all methods and properties.
|
|
95
95
|
*/
|
|
96
96
|
constructor(value: string);
|
|
97
97
|
/**
|
|
98
|
-
* * Creates a new immutable
|
|
98
|
+
* * Creates a new immutable `Chronos` instance.
|
|
99
99
|
*
|
|
100
|
-
* @param value - A date value as
|
|
100
|
+
* @param value - A date value as {@link Date} object.
|
|
101
101
|
*
|
|
102
102
|
* @returns Instance of `Chronos` with all methods and properties.
|
|
103
103
|
*/
|
|
104
104
|
constructor(value: Date);
|
|
105
105
|
/**
|
|
106
|
-
* * Creates a new immutable
|
|
106
|
+
* * Creates a new immutable `Chronos` instance.
|
|
107
107
|
*
|
|
108
108
|
* @param value - A date value as `Chronos` object.
|
|
109
109
|
*
|
|
@@ -111,10 +111,9 @@ export declare class Chronos {
|
|
|
111
111
|
*/
|
|
112
112
|
constructor(value: Chronos);
|
|
113
113
|
/**
|
|
114
|
-
* * Creates a new immutable
|
|
114
|
+
* * Creates a new immutable `Chronos` instance.
|
|
115
115
|
*
|
|
116
|
-
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
117
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
116
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
118
117
|
*
|
|
119
118
|
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99, year is assumed to be 1900 + year.
|
|
120
119
|
* @param month The month as a `number` between 1 and 12 (January to December).
|
|
@@ -128,10 +127,9 @@ export declare class Chronos {
|
|
|
128
127
|
*/
|
|
129
128
|
constructor(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number);
|
|
130
129
|
/**
|
|
131
|
-
* * Creates a new immutable
|
|
130
|
+
* * Creates a new immutable `Chronos` instance.
|
|
132
131
|
*
|
|
133
|
-
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
|
|
134
|
-
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
132
|
+
* **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
135
133
|
*
|
|
136
134
|
* @param value - A date value (`number`, `string`, `Date`, or `Chronos` object).
|
|
137
135
|
* - If a `string` is provided, it should be in a format that can be parsed by the `Date` constructor.
|
|
@@ -266,7 +266,7 @@ declare module '../Chronos' {
|
|
|
266
266
|
* @remarks This calculation is exclusive of the starting date and inclusive of the ending date.
|
|
267
267
|
*
|
|
268
268
|
* @example
|
|
269
|
-
* new Chronos('2025-12-15').workdaysBetween(
|
|
269
|
+
* new Chronos('2025-12-15').workdaysBetween('2025-12-21');
|
|
270
270
|
* // default weekend Friday & Saturday -> 4
|
|
271
271
|
*/
|
|
272
272
|
workdaysBetween(other: ChronosInput, weekStartsOn?: Enumerate<7>, weekendLength?: NumberRange<1, 4>): number;
|
|
@@ -280,10 +280,39 @@ declare module '../Chronos' {
|
|
|
280
280
|
* @remarks This calculation is exclusive of the starting date and inclusive of the ending date.
|
|
281
281
|
*
|
|
282
282
|
* @example
|
|
283
|
-
* new Chronos('2025-12-15').workdaysBetween(
|
|
283
|
+
* new Chronos('2025-12-15').workdaysBetween('2025-12-20', [0, 6]);
|
|
284
284
|
* // custom weekend Sunday & Saturday -> 4
|
|
285
285
|
*/
|
|
286
286
|
workdaysBetween(other: ChronosInput, weekendDays: RangeTuple<Enumerate<7>, 1, 4>): number;
|
|
287
|
+
/**
|
|
288
|
+
* @instance Calculates the number of weekends between the current date and another using week start day and weekend length.
|
|
289
|
+
*
|
|
290
|
+
* @param other The target date to compare against.
|
|
291
|
+
* @param weekStartsOn Optional. The day index (0–6) that the week starts on. Default is `0` (Sunday).
|
|
292
|
+
* @param weekendLength Optional. Number of consecutive days at the end of the week considered as weekend. Must be between 1 and 4. Default is `2`.
|
|
293
|
+
* @returns The total count of weekends between the two dates.
|
|
294
|
+
*
|
|
295
|
+
* @remarks This calculation is exclusive of the starting date and inclusive of the ending date.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* new Chronos('2025-12-15').weekendsBetween('2025-12-21');
|
|
299
|
+
* // default weekend Friday & Saturday -> 2
|
|
300
|
+
*/
|
|
301
|
+
weekendsBetween(other: ChronosInput, weekStartsOn?: Enumerate<7>, weekendLength?: NumberRange<1, 4>): number;
|
|
302
|
+
/**
|
|
303
|
+
* @instance Calculates the number of weekends between the current date and another using custom weekend days.
|
|
304
|
+
*
|
|
305
|
+
* @param other The target date to compare against.
|
|
306
|
+
* @param weekendDays A tuple of custom weekend day indices (0–6). Must contain 1–4 elements.
|
|
307
|
+
* @returns The total count of weekends between the two dates.
|
|
308
|
+
*
|
|
309
|
+
* @remarks This calculation is exclusive of the starting date and inclusive of the ending date.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* new Chronos('2025-12-15').weekendsBetween('2025-12-20', [0, 6]);
|
|
313
|
+
* // custom weekend Sunday & Saturday -> 1
|
|
314
|
+
*/
|
|
315
|
+
weekendsBetween(other: ChronosInput, weekendDays: RangeTuple<Enumerate<7>, 1, 4>): number;
|
|
287
316
|
/**
|
|
288
317
|
* @instance Counts the number of workdays in the current month using week start day and weekend length.
|
|
289
318
|
*
|
|
@@ -305,6 +334,27 @@ declare module '../Chronos' {
|
|
|
305
334
|
* new Chronos('2025-01-01').workdaysInMonth([0, 6]); // Sunday & Saturday are weekends
|
|
306
335
|
*/
|
|
307
336
|
workdaysInMonth(weekendDays: RangeTuple<Enumerate<7>, 1, 4>): number;
|
|
337
|
+
/**
|
|
338
|
+
* @instance Counts the number of weekends in the current month using week start day and weekend length.
|
|
339
|
+
*
|
|
340
|
+
* @param weekStartsOn Optional. The day index (0–6) that the week starts on. Default is `0` (Sunday).
|
|
341
|
+
* @param weekendLength Optional. Number of consecutive days at the end of the week considered as weekend. Must be between 1 and 4. Default is `2`.
|
|
342
|
+
* @returns Number of weekends in the current month.
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* new Chronos('2025-01-01').weekendsInMonth(); // default weekend Friday & Saturday -> 8
|
|
346
|
+
*/
|
|
347
|
+
weekendsInMonth(weekStartsOn?: Enumerate<7>, weekendLength?: NumberRange<1, 4>): number;
|
|
348
|
+
/**
|
|
349
|
+
* @instance Counts the number of weekends in the current month using custom weekend days.
|
|
350
|
+
*
|
|
351
|
+
* @param weekendDays A tuple of custom weekend day indices (0–6). Must contain 1–4 elements.
|
|
352
|
+
* @returns Number of weekends in the current month.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* new Chronos('2025-01-01').weekendsInMonth([0, 6]); // Sunday & Saturday are weekends
|
|
356
|
+
*/
|
|
357
|
+
weekendsInMonth(weekendDays: RangeTuple<Enumerate<7>, 1, 4>): number;
|
|
308
358
|
/**
|
|
309
359
|
* @instance Counts the number of workdays in the current year using week start day and weekend length.
|
|
310
360
|
*
|
|
@@ -326,6 +376,27 @@ declare module '../Chronos' {
|
|
|
326
376
|
* new Chronos('2025-01-01').workdaysInYear([0, 6]); // Sunday & Saturday are weekends
|
|
327
377
|
*/
|
|
328
378
|
workdaysInYear(weekendDays: RangeTuple<Enumerate<7>, 1, 4>): number;
|
|
379
|
+
/**
|
|
380
|
+
* @instance Counts the number of weekends in the current year using week start day and weekend length.
|
|
381
|
+
*
|
|
382
|
+
* @param weekStartsOn Optional. The day index (0–6) that the week starts on. Default is `0` (Sunday).
|
|
383
|
+
* @param weekendLength Optional. Number of consecutive days at the end of the week considered as weekend. Must be between 1–4. Default is `2`.
|
|
384
|
+
* @returns Number of weekends in the current year.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* new Chronos('2025-01-01').weekendsInYear(); // default weekend Friday & Saturday -> 104
|
|
388
|
+
*/
|
|
389
|
+
weekendsInYear(weekStartsOn?: Enumerate<7>, weekendLength?: NumberRange<1, 4>): number;
|
|
390
|
+
/**
|
|
391
|
+
* @instance Counts the number of weekends in the current year using custom weekend days.
|
|
392
|
+
*
|
|
393
|
+
* @param weekendDays A tuple of custom weekend day indices (0–6). Must contain 1–4 elements.
|
|
394
|
+
* @returns Number of weekends in the current year.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* new Chronos('2025-01-01').weekendsInYear([0, 6]); // Sunday & Saturday are weekends
|
|
398
|
+
*/
|
|
399
|
+
weekendsInYear(weekendDays: RangeTuple<Enumerate<7>, 1, 4>): number;
|
|
329
400
|
/**
|
|
330
401
|
* @instance Checks if the current time fall within business hours using week start day and weekend length & other options.
|
|
331
402
|
*
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -48,9 +48,8 @@ export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTi
|
|
|
48
48
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
49
49
|
export { averageByField, averageByField as avgByField, groupAndAverageByField, groupAndAverageByField as groupAndAvgByField, groupAndSumByField, sumByField, sumFieldDifference, sumFieldDifference as totalDeltaByField, } from './array/calc';
|
|
50
50
|
export { Finder } from './array/Finder';
|
|
51
|
-
export { sortAnArray } from './array/sort';
|
|
51
|
+
export { naturalSort as compareNaturally, naturalSort as compareSorter, naturalSort, naturalSort as naturalSortForString, sortAnArray, } from './array/sort';
|
|
52
52
|
export { createOptionsArray, getDuplicates as extractDuplicates, getDuplicates as extractDuplicatesFromArray, findMissingElements as extractMissingElements, findMissingElements, getDuplicates, getDuplicates as getDuplicatesFromArray, findMissingElements as getMissingElements, splitArrayByProperty as groupArrayByProperty, moveArrayElement, removeDuplicatesFromArray as removeDuplicates, removeDuplicatesFromArray, rotateArray, splitArray, splitArrayByProperty, } from './array/transform';
|
|
53
|
-
export { naturalSort as compareNaturally, naturalSort as compareSorter, naturalSort, naturalSort as naturalSortForString, } from './array/utils';
|
|
54
53
|
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
55
54
|
export { parseFormData, serializeForm } from './form/transform';
|
|
56
55
|
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileOrBlob, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|