nhb-toolbox 4.28.66 → 4.28.71

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 CHANGED
@@ -4,6 +4,16 @@
4
4
 
5
5
  All notable changes to the package will be documented here.
6
6
 
7
+ ## [4.28.71] - 2026-02-06
8
+
9
+ - **Fixed** an *issue* in `reconstruct` method of `Chronos` class where the *internal state* of the reconstructed instance was not properly when the timezone offset is different from the local system's timezone offset.
10
+
11
+ ## [4.28.70] - 2026-02-06
12
+
13
+ - **Added** *new static methods*: `isReconstructable` and `reconstruct` to `Chronos` class for *validating* and *reconstructing* instances from plain objects.
14
+ - **Added** `getTimestamp` utility for generating ISO 8601 timestamps with options to control input date and output format.
15
+ - **Improved** `UUID v4/v8` generation to prefer `crypto.getRandomValues` with a `Math.random` fallback when unavailable.
16
+
7
17
  ## [4.28.66] - 2026-01-23
8
18
 
9
19
  - **Refined** `TSDoc` to *improve* **IDE IntelliSense** for `Chronos` constructor.
package/README.md CHANGED
@@ -3,15 +3,15 @@
3
3
  > “I solve problems you face daily”
4
4
 
5
5
  <p>
6
- <!-- NPM Info -->
6
+ <!-- Package Info -->
7
7
  <a href="https://www.npmjs.com/package/nhb-toolbox" aria-label="NPM Downloads">
8
8
  <img src="https://img.shields.io/npm/dm/nhb-toolbox.svg?label=DOWNLOADS&style=flat&color=red&logo=npm" alt="Downloads" />
9
9
  </a>
10
10
  <a href="https://www.npmjs.com/package/nhb-toolbox" aria-label="Latest Version">
11
11
  <img src="https://img.shields.io/npm/v/nhb-toolbox.svg?label=NPM&style=flat&color=teal&logo=npm" alt="Latest Version" />
12
12
  </a>
13
- <a href="https://bundlephobia.com/result?p=nhb-toolbox" aria-label="Bundle Size">
14
- <img src="https://img.shields.io/bundlephobia/minzip/nhb-toolbox?style=flat&color=purple&label=SIZE&logo=nodedotjs" alt="Bundle Size" />
13
+ <a href="https://bundlejs.com/?q=nhb-toolbox" aria-label="Bundle Size">
14
+ <img src="https://deno.bundlejs.com/badge?q=nhb-toolbox" alt="Bundle Size" />
15
15
  </a>
16
16
 
17
17
  <!-- Project Metadata -->
@@ -515,25 +515,31 @@ debounceAction(fetchResults, 300);
515
515
 
516
516
  ## 🔗 Related Packages
517
517
 
518
- <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
518
+ <div title="React Hooks: nhb-hooks" style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
519
519
  <a target="_blank" href="https://www.npmjs.com/package/nhb-hooks">
520
520
  <img src="https://img.shields.io/badge/React_Hooks-nhb--hooks-blue" alt="nhb-hooks" />
521
521
  </a>
522
522
  </div>
523
523
 
524
- <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
524
+ <div title="IndexedDB ORM: locality-idb" style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
525
+ <a target="_blank" href="https://www.npmjs.com/package/locality-idb">
526
+ <img src="https://img.shields.io/badge/IndexedDB_ORM-locality--idb-darkviolet" alt="locality-idb" />
527
+ </a>
528
+ </div>
529
+
530
+ <div title="Development Scripts: nhb-scripts" style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
525
531
  <a target="_blank" href="https://www.npmjs.com/package/nhb-scripts">
526
532
  <img src="https://img.shields.io/badge/Development_Scripts-nhb--scripts-red" alt="nhb-scripts" />
527
533
  </a>
528
534
  </div>
529
535
 
530
- <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
536
+ <div title="Express Server Scaffolder: nhb-express" style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
531
537
  <a target="_blank" href="https://www.npmjs.com/package/nhb-express">
532
538
  <img src="https://img.shields.io/badge/Express_Server_Scaffolder-nhb--express-orange" alt="nhb-express" />
533
539
  </a>
534
540
  </div>
535
541
 
536
- <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
542
+ <div title="Anagram Generator: nhb-anagram-generator" style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
537
543
  <a target="_blank" href="https://www.npmjs.com/package/nhb-anagram-generator">
538
544
  <img src="https://img.shields.io/badge/Anagram_Generator-nhb--anagram--generator-teal" alt="nhb-anagram-generator" />
539
545
  </a>
@@ -104,9 +104,7 @@ class Chronos {
104
104
  return this.#date.getTime();
105
105
  }
106
106
  #toNewDate(value) {
107
- const date = value instanceof _a ?
108
- value.toDate()
109
- : new Date((0, primitives_1.isString)(value) ? value.replace(/['"]/g, '') : (value ?? Date.now()));
107
+ const date = value instanceof _a ? value.toDate() : (0, helpers_1._dateArgsToDate)(value);
110
108
  if (isNaN(date.getTime())) {
111
109
  throw new Error('Provided date is invalid!');
112
110
  }
@@ -807,6 +805,20 @@ class Chronos {
807
805
  static isValidChronos(value) {
808
806
  return value instanceof _a;
809
807
  }
808
+ static isReconstructable(value) {
809
+ return (0, helpers_1._hasChronosProperties)(value);
810
+ }
811
+ static reconstruct(value) {
812
+ if (!(0, helpers_1._hasChronosProperties)(value)) {
813
+ throw new TypeError('Invalid input for reconstruction!');
814
+ }
815
+ const { native, origin, utcOffset, timeZoneName, timeZoneId, $tzTracker } = value;
816
+ const offsetMins = (0, utils_1.extractMinutesFromUTC)(utcOffset);
817
+ const instance = new _a(native);
818
+ const diffMins = instance.getTimeZoneOffsetMinutes() - offsetMins;
819
+ const target = instance.utcOffset === utcOffset ? instance : instance.add(-diffMins, 'minute');
820
+ return target.#withOrigin(origin, utcOffset, timeZoneName, timeZoneId, $tzTracker);
821
+ }
810
822
  static use(plugin) {
811
823
  if (!_a.#plugins.has(plugin)) {
812
824
  _a.#plugins.add(plugin);
@@ -16,6 +16,11 @@ exports._getElapsedDays = _getElapsedDays;
16
16
  exports._bnDaysMonthIdx = _bnDaysMonthIdx;
17
17
  exports._padZero = _padZero;
18
18
  exports._padShunno = _padShunno;
19
+ exports._dateArgsToDate = _dateArgsToDate;
20
+ exports._hasChronosProperties = _hasChronosProperties;
21
+ const non_primitives_1 = require("../guards/non-primitives");
22
+ const primitives_1 = require("../guards/primitives");
23
+ const specials_1 = require("../guards/specials");
19
24
  const utilities_1 = require("../number/utilities");
20
25
  const constants_1 = require("./constants");
21
26
  const guards_1 = require("./guards");
@@ -150,3 +155,20 @@ function _padZero(value, length = 2) {
150
155
  function _padShunno(str, length = 2) {
151
156
  return str.padStart(length, '০');
152
157
  }
158
+ function _dateArgsToDate(value) {
159
+ return (0, non_primitives_1.isDate)(value) ? value : (new Date((0, primitives_1.isString)(value) ? value.replace(/['"]/g, '') : (value ?? Date.now())));
160
+ }
161
+ function _hasChronosProperties(value) {
162
+ return ((0, non_primitives_1.isObjectWithKeys)(value, [
163
+ 'origin',
164
+ 'native',
165
+ 'utcOffset',
166
+ 'timeZoneName',
167
+ 'timeZoneId',
168
+ ]) &&
169
+ (0, primitives_1.isNonEmptyString)(value.origin) &&
170
+ ((0, non_primitives_1.isDate)(value.native) || (0, specials_1.isDateString)(value.native)) &&
171
+ (0, guards_1.isValidUTCOffset)(value.utcOffset) &&
172
+ (0, primitives_1.isNonEmptyString)(value.timeZoneName) &&
173
+ ((0, primitives_1.isNonEmptyString)(value.timeZoneId) || (0, non_primitives_1.isValidArray)(value.timeZoneId)));
174
+ }
@@ -12,7 +12,8 @@ exports.getTimeZoneDetails = getTimeZoneDetails;
12
12
  exports.getTimeZoneIds = getTimeZoneIds;
13
13
  exports.formatDate = formatDate;
14
14
  exports.formatTimePart = formatTimePart;
15
- const primitives_1 = require("../guards/primitives");
15
+ exports.getTimestamp = getTimestamp;
16
+ const non_primitives_1 = require("../guards/non-primitives");
16
17
  const guards_1 = require("./guards");
17
18
  const helpers_1 = require("./helpers");
18
19
  const timezone_1 = require("./timezone");
@@ -76,7 +77,7 @@ function getTimeZoneIds(offset) {
76
77
  }
77
78
  function formatDate(options) {
78
79
  const { date = new Date(), format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false, } = options ?? {};
79
- const $date = date instanceof Date ? date : (new Date((0, primitives_1.isString)(date) ? date.replace(/['"]/g, '') : date));
80
+ const $date = (0, helpers_1._dateArgsToDate)(date);
80
81
  if (isNaN($date.getTime())) {
81
82
  return 'Invalid Date!';
82
83
  }
@@ -91,3 +92,29 @@ function formatTimePart(time, format) {
91
92
  const timeWithDate = `${formatDate({ format: 'YYYY-MM-DD' })}T${(0, helpers_1._normalizeOffset)(time)}`;
92
93
  return formatDate({ date: timeWithDate, format: format || 'hh:mm:ss a' });
93
94
  }
95
+ function getTimestamp(args, format) {
96
+ let $value;
97
+ let $format;
98
+ const _isTsOptions = (opt) => {
99
+ return (0, non_primitives_1.isObject)(opt) && ('value' in opt || 'format' in opt);
100
+ };
101
+ if (_isTsOptions(args)) {
102
+ $value = args.value || new Date();
103
+ $format = args.format || 'utc';
104
+ }
105
+ else {
106
+ $value = args || new Date();
107
+ $format = format || 'utc';
108
+ }
109
+ let date = (0, helpers_1._dateArgsToDate)($value);
110
+ if (isNaN(date.getTime())) {
111
+ date = new Date();
112
+ }
113
+ if ($format === 'local') {
114
+ const offsetMins = date.getTimezoneOffset();
115
+ const localDate = new Date(date.getTime() - offsetMins * 60000);
116
+ const offset = formatUTCOffset(-offsetMins).slice(3);
117
+ return localDate.toISOString().replace('Z', offset);
118
+ }
119
+ return date.toISOString();
120
+ }
@@ -43,8 +43,13 @@ function uuid(options) {
43
43
  }
44
44
  case 'v4': {
45
45
  const bytes = new Uint8Array(16);
46
- for (let i = 0; i < 16; i++) {
47
- bytes[i] = Math.floor(Math.random() * 256);
46
+ if (crypto.getRandomValues) {
47
+ crypto.getRandomValues(bytes);
48
+ }
49
+ else {
50
+ for (let i = 0; i < 16; i++) {
51
+ bytes[i] = Math.floor(Math.random() * 256);
52
+ }
48
53
  }
49
54
  let hex = '';
50
55
  for (let i = 0; i < 16; i++) {
@@ -88,8 +93,13 @@ function uuid(options) {
88
93
  bytes[i] = Number(temp & 0xffn);
89
94
  temp >>= 8n;
90
95
  }
91
- for (let i = 6; i < 16; i++) {
92
- bytes[i] = Math.floor(Math.random() * 256);
96
+ if (crypto.getRandomValues) {
97
+ crypto.getRandomValues(bytes);
98
+ }
99
+ else {
100
+ for (let i = 6; i < 16; i++) {
101
+ bytes[i] = Math.floor(Math.random() * 256);
102
+ }
93
103
  }
94
104
  let hex = '';
95
105
  for (let i = 0; i < 16; i++) {
package/dist/cjs/index.js CHANGED
@@ -4,11 +4,11 @@ exports.convertToDecimal = exports.calculateLCM = exports.calculateLCD = exports
4
4
  exports.convertRomanToInteger = exports.convertRomanToArabic = exports.convertNumberToWordsOrdinal = exports.convertNumberToWords = exports.cardinalWordsToOrdinal = exports.banglaToDigit = 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.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.digitToBangla = exports.convertWordToNumber = exports.convertWordsToNumber = exports.convertToRomanNumerals = exports.convertRomanToNumeric = void 0;
6
6
  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.Bongabdo = exports.BnCalendar = exports.BanglaCalendar = 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 = exports.convertHslToHex = exports.convertHslaToRgba = void 0;
7
- 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 = exports.formatTimePart = exports.formatDateTime = exports.formatDate = exports.extractTotalMinutesFromTime = exports.extractTimeStringFromUTC = exports.extractTimeFromUTC = void 0;
8
- 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 = exports.convertIntoFormData = exports.splitArrayByProperty = exports.splitArray = exports.rotateArray = exports.removeDuplicatesFromArray = exports.removeDuplicates = void 0;
9
- 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 = exports.parseQueryStringLiteral = exports.parseQueryString = exports.literalQueryStringToObject = exports.getQueryStringAsObject = exports.getQueryParams = exports.generateQueryParams = void 0;
10
- exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isHexString = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBinaryString = 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 = exports.isArrayOfType = exports.isArray = exports.doesReturnPromise = exports.isUndefined = exports.isTruthy = exports.isSymbol = void 0;
11
- exports.isValidURL = exports.isValidEmail = void 0;
7
+ 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.getTimestamp = exports.getCurrentTime = exports.getCurrentDateTime = exports.formatUTCOffset = exports.formatTimePart = exports.formatDateTime = exports.formatDate = exports.extractTotalMinutesFromTime = exports.extractTimeStringFromUTC = exports.extractTimeFromUTC = void 0;
8
+ 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 = exports.convertIntoFormData = exports.splitArrayByProperty = exports.splitArray = exports.rotateArray = exports.removeDuplicatesFromArray = exports.removeDuplicates = exports.moveArrayElement = void 0;
9
+ 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 = exports.parseQueryStringLiteral = exports.parseQueryString = exports.literalQueryStringToObject = exports.getQueryStringAsObject = exports.getQueryParams = exports.generateQueryParams = exports.formatQueryParams = void 0;
10
+ exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isHexString = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBinaryString = 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 = exports.isArrayOfType = exports.isArray = exports.doesReturnPromise = exports.isUndefined = exports.isTruthy = exports.isSymbol = exports.isString = void 0;
11
+ exports.isValidURL = exports.isValidEmail = exports.isUUID = void 0;
12
12
  var basics_1 = require("./string/basics");
13
13
  Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
14
14
  Object.defineProperty(exports, "trimString", { enumerable: true, get: function () { return basics_1.trimString; } });
@@ -251,6 +251,7 @@ Object.defineProperty(exports, "formatTimePart", { enumerable: true, get: functi
251
251
  Object.defineProperty(exports, "formatUTCOffset", { enumerable: true, get: function () { return utils_2.formatUTCOffset; } });
252
252
  Object.defineProperty(exports, "getCurrentDateTime", { enumerable: true, get: function () { return utils_2.getCurrentDateTime; } });
253
253
  Object.defineProperty(exports, "getCurrentTime", { enumerable: true, get: function () { return utils_2.getCurrentDateTime; } });
254
+ Object.defineProperty(exports, "getTimestamp", { enumerable: true, get: function () { return utils_2.getTimestamp; } });
254
255
  Object.defineProperty(exports, "getHourMinutesFromMinutes", { enumerable: true, get: function () { return utils_2.convertMinutesToTime; } });
255
256
  Object.defineProperty(exports, "getMinutesFromUTC", { enumerable: true, get: function () { return utils_2.extractMinutesFromUTC; } });
256
257
  Object.defineProperty(exports, "getNativeTimeZoneId", { enumerable: true, get: function () { return utils_2.getNativeTimeZoneId; } });
@@ -1,7 +1,7 @@
1
1
  import type { Enumerate, NumberRange } from '../number/types';
2
2
  import type { LooseLiteral, TupleOf } from '../utils/types';
3
3
  import { INTERNALS } from './constants';
4
- import type { $NativeTzNameOrId, $TimeZoneIdentifier, $UTCOffset, ChronosInput, ChronosInternals, ChronosMethods, ChronosObject, ChronosPlugin, ChronosWithOptions, DateRangeOptions, DateTimeFormatOptions, FormatOptions, LocalesArguments, Milliseconds, MonthName, Quarter, RangeWithDates, RelativeDateRange, RelativeRangeOptions, StrictFormat, TimeOnlyFormat, TimeUnit, TimeUnitValue, TimeZone, TimeZoneId, TimeZoneIdNative, TimeZoneName, UTCOffset, WeekDay } from './types';
4
+ import type { $NativeTzNameOrId, $TimeZoneIdentifier, $UTCOffset, ChronosInput, ChronosInternals, ChronosMethods, ChronosObject, ChronosPlugin, ChronosProperties, ChronosWithOptions, DateRangeOptions, DateTimeFormatOptions, FormatOptions, LocalesArguments, Milliseconds, MonthName, Quarter, RangeWithDates, RelativeDateRange, RelativeRangeOptions, StrictFormat, TimeOnlyFormat, TimeUnit, TimeUnitValue, TimeZone, TimeZoneId, TimeZoneIdNative, TimeZoneName, UTCOffset, WeekDay } from './types';
5
5
  /**
6
6
  * @class Creates a new immutable `Chronos` instance.
7
7
  * - **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
@@ -822,6 +822,23 @@ export declare class Chronos {
822
822
  * @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
823
823
  */
824
824
  static isValidChronos(value: unknown): value is Chronos;
825
+ /**
826
+ * @static Checks if the given value has the necessary properties to be reconstructed into a `Chronos` instance.
827
+ * - Can be used for validating objects that may represent serialized `Chronos` data.
828
+ * @param value - The value to check.
829
+ * @returns `true` if the value has the required properties for reconstruction, otherwise `false`.
830
+ */
831
+ static isReconstructable(value: unknown): value is ChronosProperties;
832
+ /**
833
+ * @static Reconstructs a `Chronos` instance from an object containing the necessary properties.
834
+ * - The input object must have the properties defined in {@link ChronosProperties} interface.
835
+ * - If the input is not reconstructable, an error is thrown.
836
+ *
837
+ * @param value - An object containing the properties required to reconstruct a `Chronos` instance.
838
+ * @returns A new `Chronos` instance created from the provided properties.
839
+ * @throws `TypeError` if the input value does not have the necessary properties for reconstruction.
840
+ */
841
+ static reconstruct(value: ChronosProperties): Chronos;
825
842
  /**
826
843
  * @static Injects a plugin into the `Chronos` system.
827
844
  * @param plugin The plugin to inject.
@@ -40,6 +40,8 @@ import type { ChronosStatics } from './types';
40
40
  * chronos.isValidDate(value: unknown): boolean;
41
41
  * chronos.isDateString(value: unknown): boolean;
42
42
  * chronos.isValidChronos(value: unknown): boolean;
43
+ * chronos.isReconstructable(value: unknown): value is ChronosProperties;
44
+ * chronos.reconstruct(value: ChronosProperties): Chronos;
43
45
  * chronos.formatTimePart(time: string, format?: TimeParts): string;
44
46
  * chronos.getDatesForDay(day: WeekDay, options?: WeekdayOptions): string[];
45
47
  * chronos.use(plugin: ChronosPlugin): void;
@@ -1,5 +1,5 @@
1
1
  import type { Chronos } from './Chronos';
2
- import type { ChronosInput, ChronosPlugin, ChronosWithOptions, DateRangeOptions, FormatOptions, RelativeRangeOptions, TimeFormatToken, WeekDay, WeekdayOptions } from './types';
2
+ import type { ChronosInput, ChronosPlugin, ChronosProperties, ChronosWithOptions, DateRangeOptions, FormatOptions, RelativeRangeOptions, TimeFormatToken, WeekDay, WeekdayOptions } from './types';
3
3
  /** All the statics methods in `Chronos` class */
4
4
  export interface ChronosStatics {
5
5
  /**
@@ -302,4 +302,21 @@ export interface ChronosStatics {
302
302
  * @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
303
303
  */
304
304
  isValidChronos(value: unknown): value is Chronos;
305
+ /**
306
+ * * Checks if the given value has the necessary properties to be reconstructed into a `Chronos` instance.
307
+ * - Can be used for validating objects that may represent serialized `Chronos` data.
308
+ * @param value - The value to check.
309
+ * @returns `true` if the value has the required properties for reconstruction, otherwise `false`.
310
+ */
311
+ isReconstructable(value: unknown): value is ChronosProperties;
312
+ /**
313
+ * * Reconstructs a `Chronos` instance from an object containing the necessary properties.
314
+ * - The input object must have the properties defined in {@link ChronosProperties} interface.
315
+ * - If the input is not reconstructable, an error is thrown.
316
+ *
317
+ * @param value - An object containing the properties required to reconstruct a `Chronos` instance.
318
+ * @returns A new `Chronos` instance created from the provided properties.
319
+ * @throws `TypeError` if the input value does not have the necessary properties for reconstruction.
320
+ */
321
+ reconstruct(value: ChronosProperties): Chronos;
305
322
  }
@@ -1,6 +1,6 @@
1
1
  import type { Enumerate, NumberRange } from '../number/types';
2
2
  import type { Maybe } from '../types/index';
3
- import type { $BnEn, $GMTOffset, $TimeZoneIdentifier, BanglaSeasonName, BnCalendarVariant, TimeZoneNameNative } from './types';
3
+ import type { $BnEn, $GMTOffset, $TimeZoneIdentifier, BanglaSeasonName, BnCalendarVariant, ChronosProperties, DateArgs, TimeZoneNameNative } from './types';
4
4
  /** Core formatting logic shared by `formatDate` and `Chronos`, `BanglaCalendar` classes */
5
5
  export declare function _formatDateCore(format: string, dateComponents: Record<string, string>): string;
6
6
  /** Core formatting logic shared by `formatDate` and `Chronos` class */
@@ -57,4 +57,20 @@ export declare function _padZero(value: number, length?: number): string;
57
57
  * @returns The padded string
58
58
  */
59
59
  export declare function _padShunno(str: string, length?: number): string;
60
+ /**
61
+ * Convert a string, number, or `Date` object to a `Date` object.
62
+ * - If the input is already a `Date`, it is returned as is.
63
+ * - If it's a string, it is parsed into a `Date`.
64
+ * - If it's a number or undefined, it is treated as a timestamp and converted to a `Date`.
65
+ * @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).
66
+ * @returns A `Date` object representing the input date.
67
+ */
68
+ export declare function _dateArgsToDate(value: Maybe<DateArgs>): Date;
69
+ /**
70
+ * Type guard to check if a value has the necessary properties to be reconstructed into a `Chronos` instance.
71
+ * - Validates that the value is an object with the required keys and that the `native` property is a valid date or date string, and that the `utcOffset` is valid.
72
+ * @param value The value to check for reconstructability.
73
+ * @returns `true` if the value has the required properties for reconstruction, otherwise `false`.
74
+ */
75
+ export declare function _hasChronosProperties(value: unknown): value is ChronosProperties;
60
76
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { $BnOnes, BanglaDigit, Enumerate, LocaleCode, NumberRange } from '../number/types';
2
- import type { Maybe } from '../types/index';
2
+ import type { Branded, Maybe } from '../types/index';
3
3
  import type { LooseLiteral, RangeTuple, Repeat, Split } from '../utils/types';
4
4
  import type { Chronos } from './Chronos';
5
5
  import type { ChronosStatics } from './chronos-statics';
@@ -62,7 +62,7 @@ export type TimeZoneDetails = {
62
62
  /** Options for `formatDate` utility */
63
63
  export interface DateFormatOptions extends FormatOptions {
64
64
  /** - Date to format, must be parsable by {@link Date} constructor. Can be string, number or `Date`. Defaults to current time. */
65
- date?: string | number | Date;
65
+ date?: DateArgs;
66
66
  format?: StrictFormat;
67
67
  }
68
68
  /** Name of time unit from `year` to `millisecond` */
@@ -248,6 +248,21 @@ export type ChronosMethods = $InstanceMethods | $StaticMethods | $PluginMethods;
248
248
  * and convert it to the **equivalent local time** using the current environment's UTC offset.*
249
249
  */
250
250
  export type ChronosInput = number | string | Date | Chronos;
251
+ /** Properties required to reconstruct a `Chronos` instance. */
252
+ export interface ChronosProperties {
253
+ /** The method or plugin name from which the instance was created. */
254
+ origin: LooseLiteral<ChronosMethods>;
255
+ /** The native date value, either as a `Date` object or a date string. */
256
+ native: Date | string;
257
+ /** The UTC offset in `UTC±HH:mm` format. */
258
+ utcOffset: UTCOffset;
259
+ /** The full time zone name (e.g., `"Pacific Standard Time"`). */
260
+ timeZoneName: LooseLiteral<TimeZoneName>;
261
+ /** The time zone identifier(s) associated with the instance (e.g., `"Asia/Dhaka"`). */
262
+ timeZoneId: TimeZoneId;
263
+ /** Optional tracker to identify the instance created by `timeZone` method. */
264
+ $tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset;
265
+ }
251
266
  /** Represents key of `ChronosStatics` (each static method and property) */
252
267
  export type ChronosStaticKey = keyof ChronosStatics;
253
268
  /** Key of {@link TIME_ZONE_LABELS} ({@link UTCOffset}) */
@@ -280,6 +295,26 @@ export type $UTCOffset = `${PositiveUTCHour | NegativeUTCHour}:${UTCMinute}`;
280
295
  export type UTCOffset = `UTC${$UTCOffset}`;
281
296
  /** GMT offset in `GMT±HH:mm` or simply `GMT` format */
282
297
  export type $GMTOffset = `GMT${$UTCOffset}` | 'GMT';
298
+ /** Timestamp string type in ISO 8601 format */
299
+ export type Timestamp = Branded<string, 'Timestamp'>;
300
+ /** Valid argument type accepted by `Date` constructor */
301
+ export type DateArgs = string | number | Date;
302
+ /** Type for ISO date format options */
303
+ export type ISODateFormat = 'local' | 'utc';
304
+ /** Options for `getTimestamp` utility */
305
+ export interface TimestampOptions {
306
+ /**
307
+ * Optional date input (string, number, or `Date` object).
308
+ * Defaults to {@link Date new Date()}.
309
+ */
310
+ value?: DateArgs;
311
+ /**
312
+ * Output format for the timestamp.
313
+ * - `'utc'` (default) → returns ISO string in UTC (`...Z`).
314
+ * - `'local'` → returns ISO string with current system offset (`...+05:30`).
315
+ */
316
+ format?: ISODateFormat;
317
+ }
283
318
  /** `Chronos` Date Format options */
284
319
  export interface FormatOptions {
285
320
  /**
@@ -349,7 +384,7 @@ export type MonthName = (typeof MONTHS)[number];
349
384
  /** Common options for formatting and rounding dates */
350
385
  interface $CommonRangeOptions {
351
386
  /** - Output format: return ISO strings in `'local'` or `'utc'` format. Defaults to `'local'`. */
352
- format?: 'local' | 'utc';
387
+ format?: ISODateFormat;
353
388
  /** - Whether to round the dates in the range to the start of the day. Default is `false`. */
354
389
  roundDate?: boolean;
355
390
  }
@@ -1,5 +1,5 @@
1
1
  import type { Numeric } from '../types/index';
2
- import type { $TimeZoneIdentifier, ClockTime, DateFormatOptions, HourMinutes, TimeOnlyFormat, TimeZoneDetails, TimeZoneIdNative, UTCOffset } from './types';
2
+ import type { $TimeZoneIdentifier, ClockTime, DateArgs, DateFormatOptions, HourMinutes, ISODateFormat, TimeOnlyFormat, TimeZoneDetails, TimeZoneIdNative, Timestamp, TimestampOptions, UTCOffset } from './types';
3
3
  /**
4
4
  * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
5
5
  *
@@ -18,6 +18,8 @@ export declare function getTotalMinutes(time: `-${ClockTime}` | ClockTime): numb
18
18
  * * Returns the current date and time as `Date` object.
19
19
  * - All the methods and properties of `new Date()` are accessible.
20
20
  *
21
+ * @remarks This function is a simple wrapper around `new Date()` and is provided for consistency and potential future enhancements.
22
+ *
21
23
  * @returns The current date and time as a `Date` object.
22
24
  */
23
25
  export declare function getCurrentDateTime(): Date;
@@ -83,7 +85,7 @@ export declare function getTimeZoneIds(offset: UTCOffset): TimeZoneIdNative[];
83
85
  *
84
86
  * @remarks
85
87
  * - If no date is provided, the current date and time will be used.
86
- * - If the provided date is invalid, the function will return `"Invalid Date!"`.
88
+ * - If the provided date is invalid, the function will return `'Invalid Date!'`.
87
89
  * - The default format is `'dd, mmm DD, YYYY HH:mm:ss'` (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
88
90
  * - By default, local time is used; set `useUTC` to `true` to format in UTC.
89
91
  * - The format string supports various tokens for date and time components, as well as literal text enclosed in square brackets.
@@ -114,3 +116,44 @@ export declare function formatDate(options?: DateFormatOptions): string;
114
116
  * @returns Formatted time string in local (System) time.
115
117
  */
116
118
  export declare function formatTimePart(time: string, format?: TimeOnlyFormat): string;
119
+ /**
120
+ * * Get timestamp in ISO 8601 format.
121
+ *
122
+ * @param value - Date value to convert to timestamp. Supported formats include:
123
+ * - `Date` object → e.g., `new Date()`
124
+ * - Date string → e.g., `'2025-04-06'`, `'2025-04-06 16:11:55'`, `'April 6, 2025 16:11:55'` etc.
125
+ * - Timestamp number → e.g., `1712748715000`
126
+ *
127
+ * @remarks If the provided {@link value} is invalid, the current date and time will be used.
128
+ *
129
+ * @returns Timestamp string in ISO 8601 format.
130
+ */
131
+ export declare function getTimestamp(): Timestamp;
132
+ /**
133
+ * * Get timestamp in ISO 8601 format.
134
+ *
135
+ * @param value - Date value to convert to timestamp. Supported formats include:
136
+ * - `Date` object → e.g., `new Date()`
137
+ * - Date string → e.g., `'2025-04-06'`, `'2025-04-06 16:11:55'`, `'April 6, 2025 16:11:55'` etc.
138
+ * - Timestamp number → e.g., `1712748715000`
139
+ * @param format - Format of the output timestamp.
140
+ * - Use `format: 'local'` to include the current system timezone offset.
141
+ * - Default is `'utc'` which returns timestamp in UTC format (ending with 'Z').
142
+ *
143
+ * @remarks If the provided {@link value} is invalid, the current date and time will be used.
144
+ *
145
+ * @returns Timestamp string in ISO 8601 format.
146
+ */
147
+ export declare function getTimestamp(value: DateArgs, format?: ISODateFormat): Timestamp;
148
+ /**
149
+ * * Get timestamp in ISO 8601 format.
150
+ *
151
+ * @param options Options to control date input and output format.
152
+ *
153
+ * @remarks
154
+ * - If the provided {@link TimestampOptions.value value} is invalid, the current date and time will be used.
155
+ * - Use `format: 'local'` to include the current system timezone offset.
156
+ *
157
+ * @returns Timestamp string in ISO 8601 format.
158
+ */
159
+ export declare function getTimestamp(options?: TimestampOptions): Timestamp;
@@ -34,8 +34,9 @@ import type { DecodedUUID, SupportedVersion, UUID, UUIDOptions } from './types';
34
34
  * - This utility provides a complete, engine-agnostic UUID generator with full RFC compliance, predictable formatting, and reliable uniqueness characteristics, suitable for browsers, Node.js, and restricted JavaScript runtimes.
35
35
  * - **Notes**
36
36
  * - `v1` and `v6` use a generated pseudo-node identifier.
37
- * - `v4`, `v7`, `v8` **do not rely on crypto APIs**, preserving engine-agnostic behavior.
37
+ * - `v4` and `v8` uses {@link Math.random} when {@link crypto.getRandomValues} is unavailable, ensuring broad compatibility.
38
38
  * - `v3` and `v5` use internal `MD5`/`SHA-1` implementations and remain fully deterministic.
39
+ * - `v7` **do not rely on crypto APIs**, preserving engine-agnostic behavior.
39
40
  *
40
41
  * - **Limitations**
41
42
  * - `v1`/`v6`: Node identifier is pseudo-random, not derived from real MAC addresses (for privacy).
@@ -45,7 +45,7 @@ export { BanglaCalendar, BnCalendar, Bongabdo } from './date/BanglaCalendar';
45
45
  export { Chronos, Chronus } from './date/Chronos';
46
46
  export { INTERNALS } from './date/constants';
47
47
  export { chronos, chronosjs, chronosts, chronus, chronusjs, chronusts, } from './date/chronos-fn';
48
- export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatTimePart, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, convertMinutesToTime as getHourMinutesFromMinutes, extractMinutesFromUTC as getMinutesFromUTC, getNativeTimeZoneId, convertMinutesToTime as getTimeFromMinutes, extractTimeFromUTC as getTimeStringFromUTC, getTimeZoneDetails, getTimeZoneIds, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils';
48
+ export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatTimePart, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, getTimestamp, convertMinutesToTime as getHourMinutesFromMinutes, extractMinutesFromUTC as getMinutesFromUTC, getNativeTimeZoneId, convertMinutesToTime as getTimeFromMinutes, extractTimeFromUTC as getTimeStringFromUTC, getTimeZoneDetails, getTimeZoneIds, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils';
49
49
  export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
50
50
  export { averageByField, averageByField as avgByField, groupAndAverageByField, groupAndAverageByField as groupAndAvgByField, groupAndSumByField, sumByField, sumFieldDifference, sumFieldDifference as totalDeltaByField, } from './array/calc';
51
51
  export { Finder } from './array/Finder';
@@ -150,7 +150,7 @@ export declare function stripJsonEdgeGarbage(str: string): string;
150
150
  /**
151
151
  * * Parses any valid JSON string, optionally converting stringified primitives inside (nested) arrays or objects.
152
152
  *
153
- * @template T - Expected return type (default is unknown).
153
+ * @typeParam T - Expected return type (default is unknown).
154
154
  * @param value - The JSON string to parse.
155
155
  * @param parsePrimitives - Whether to convert stringified primitives (default: `true`).
156
156
  * @returns The parsed JSON value typed as `T`, or the original parsed value with optional primitive conversion.
@@ -167,7 +167,7 @@ export declare const parseJSON: <T = unknown>(value: string, parsePrimitives?: b
167
167
  /**
168
168
  * * Recursively parses primitive values inside objects and arrays.
169
169
  *
170
- * @template T - Expected return type after parsing (default is unknown).
170
+ * @typeParam T - Expected return type after parsing (default is unknown).
171
171
  * @param input - Any input value to parse recursively.
172
172
  * @returns Input with primitives (strings like "true", "123") converted, typed as `T`.
173
173
  */
@@ -236,7 +236,7 @@ export type LooseLiteral<T extends string | number> = T | (T extends string ? st
236
236
  /**
237
237
  * * Extracts an object type containing only the optional keys from `T`.
238
238
  *
239
- * @template T - The original object type
239
+ * @typeParam T - The original object type
240
240
  * @returns A new object type with only optional keys from `T`
241
241
  * @example
242
242
  * type Example = { a: string; b?: number; c?: boolean };
@@ -249,7 +249,7 @@ export type ExtractOptional<T> = {
249
249
  /**
250
250
  * * Extracts an object type containing only the required keys from `T`.
251
251
  *
252
- * @template T - The original object type
252
+ * @typeParam T - The original object type
253
253
  * @returns A new object type with only required keys from `T`
254
254
  * @example
255
255
  * type Example = { a: string; b?: number; c: boolean };
@@ -262,7 +262,7 @@ export type ExtractRequired<T> = {
262
262
  /**
263
263
  * * Converts a readonly tuple to a union of its element types.
264
264
  *
265
- * @template T - A tuple type (must be readonly if using `as const`)
265
+ * @typeParam T - A tuple type (must be readonly if using `as const`)
266
266
  * @example
267
267
  * const roles = ['admin', 'user', 'guest'] as const;
268
268
  * type Role = TupleToUnion<typeof roles>; // "admin" | "user" | "guest"
@@ -300,8 +300,8 @@ export type RangeTuple<T, Min extends number, Max extends number> = $Range<Min,
300
300
  * If `K` is provided, only those properties' values become optional (keys remain required).
301
301
  * If `K` is omitted, all property values become optional.
302
302
  *
303
- * @template O - The original object type.
304
- * @template K - Optional union of keys in `O` whose values should become optional.
303
+ * @typeParam O - The original object type.
304
+ * @typeParam K - Optional union of keys in `O` whose values should become optional.
305
305
  *
306
306
  * @example
307
307
  * type A = { name: string; age: number };
@@ -321,8 +321,8 @@ export type $Without<T, U> = {
321
321
  /**
322
322
  * * Creates a type that is either `T` or `U`, but not both at the same time.
323
323
  * * This is useful for defining types that can be one of two options, but not both.
324
- * * @template T - First type option.
325
- * @template U - Second type option.
324
+ * @typeParam T - First type option.
325
+ * @typeParam U - Second type option.
326
326
  * @example
327
327
  * type A = { a: string };
328
328
  * type B = { b: number };
@@ -333,7 +333,7 @@ export type OneOf<T, U> = (T & $Without<U, T>) | (U & $Without<T, U>);
333
333
  /**
334
334
  * * Checks whether a type is a strict object (excluding functions).
335
335
  *
336
- * @template T - The type to test.
336
+ * @typeParam T - The type to test.
337
337
  *
338
338
  * @example
339
339
  * type A = IsStrictObject<{}>; // false
@@ -346,7 +346,7 @@ export type IsStrictObject<T> = T extends object ? T extends AdvancedTypes ? fal
346
346
  * * Returns the keyof `T` only if `T` is a non-function object, otherwise `null`.
347
347
  * * Prevents extracting keys from primitives or functions.
348
348
  *
349
- * @template T - The input type.
349
+ * @typeParam T - The input type.
350
350
  *
351
351
  * @example
352
352
  * type A = Keyof<{ x: number }>; // "x"
@@ -356,7 +356,7 @@ export type Keyof<T> = IsStrictObject<T> extends true ? keyof T : null;
356
356
  /**
357
357
  * * Recursively generates dot-separated keys from a nested object.
358
358
  *
359
- * @template T - The input nested object type.
359
+ * @typeParam T - The input nested object type.
360
360
  *
361
361
  * @example
362
362
  * type Obj = { user: { name: string; meta: { id: number } } };
@@ -369,8 +369,8 @@ export type DeepKeyof<T> = IsStrictObject<T> extends true ? {
369
369
  /**
370
370
  * * Creates a new type by picking properties from `T` whose values extend type `V`.
371
371
  *
372
- * @template T - The object type.
373
- * @template V - The value type to filter by.
372
+ * @typeParam T - The object type.
373
+ * @typeParam V - The value type to filter by.
374
374
  *
375
375
  * @example
376
376
  * type T = { name: string; age: number; active: boolean };
@@ -382,8 +382,8 @@ export type PickByValue<T, V> = {
382
382
  /**
383
383
  * * Maps all values of object `T` to a fixed type `R`, keeping original keys.
384
384
  *
385
- * @template T - The source object type.
386
- * @template R - The replacement value type.
385
+ * @typeParam T - The source object type.
386
+ * @typeParam R - The replacement value type.
387
387
  *
388
388
  * @example
389
389
  * type T = { name: string; age: number };
@@ -396,7 +396,7 @@ export type MapObjectValues<T, R> = {
396
396
  * * Removes properties from object `T` whose type is `never`.
397
397
  * * Typically useful after conditional filtering.
398
398
  *
399
- * @template T - The input object type.
399
+ * @typeParam T - The input object type.
400
400
  *
401
401
  * @example
402
402
  * type T = { a: string; b: never; c: number };
@@ -408,8 +408,8 @@ export type RemoveNever<T> = {
408
408
  /**
409
409
  * * Renames the keys of `T` using the mapping `R`.
410
410
  *
411
- * @template T - Original object type.
412
- * @template R - Mapping from original keys to new key names.
411
+ * @typeParam T - Original object type.
412
+ * @typeParam R - Mapping from original keys to new key names.
413
413
  *
414
414
  * @example
415
415
  * type Original = { first: string; last: string };
@@ -430,8 +430,8 @@ export type $Forbid<T, K extends keyof T> = {
430
430
  /**
431
431
  * * Enforces that at least `N` properties of type `T` are required.
432
432
  *
433
- * @template T - The base object type.
434
- * @template N - The minimum number of required properties.
433
+ * @typeParam T - The base object type.
434
+ * @typeParam N - The minimum number of required properties.
435
435
  *
436
436
  * @example
437
437
  * interface User {
@@ -462,8 +462,8 @@ export type RequireAtLeast<T extends GenericObject, N extends number, Keys exten
462
462
  * * Enforces that exactly `N` properties of type `T` are required.
463
463
  * * All other properties remain forbidden.
464
464
  *
465
- * @template T - The base object type.
466
- * @template N - The exact number of required properties.
465
+ * @typeParam T - The base object type.
466
+ * @typeParam N - The exact number of required properties.
467
467
  *
468
468
  * @example
469
469
  * interface Config {
@@ -492,9 +492,9 @@ export type RequireExactly<T extends GenericObject, N extends number> = {
492
492
  /**
493
493
  * * Enforces that between `Min` and `Max` properties of type `T` are required.
494
494
  *
495
- * @template T - The base object type.
496
- * @template Min - The minimum number of required properties.
497
- * @template Max - The maximum number of required properties.
495
+ * @typeParam T - The base object type.
496
+ * @typeParam Min - The minimum number of required properties.
497
+ * @typeParam Max - The maximum number of required properties.
498
498
  *
499
499
  * @example
500
500
  * interface Settings {
@@ -3,7 +3,7 @@ import { isValidArray } from '../guards/non-primitives.js';
3
3
  import { isNumber, isString } from '../guards/primitives.js';
4
4
  import { DAYS, INTERNALS, MONTHS, MS_PER_DAY } from './constants.js';
5
5
  import { isLeapYear } from './guards.js';
6
- import { _formatDate, _normalizeOffset, _resolveNativeTzName } from './helpers.js';
6
+ import { _dateArgsToDate, _formatDate, _hasChronosProperties, _normalizeOffset, _resolveNativeTzName, } from './helpers.js';
7
7
  import { extractMinutesFromUTC, getNativeTimeZoneId } from './utils.js';
8
8
  export class Chronos {
9
9
  #date;
@@ -101,9 +101,7 @@ export class Chronos {
101
101
  return this.#date.getTime();
102
102
  }
103
103
  #toNewDate(value) {
104
- const date = value instanceof _a ?
105
- value.toDate()
106
- : new Date(isString(value) ? value.replace(/['"]/g, '') : (value ?? Date.now()));
104
+ const date = value instanceof _a ? value.toDate() : _dateArgsToDate(value);
107
105
  if (isNaN(date.getTime())) {
108
106
  throw new Error('Provided date is invalid!');
109
107
  }
@@ -804,6 +802,20 @@ export class Chronos {
804
802
  static isValidChronos(value) {
805
803
  return value instanceof _a;
806
804
  }
805
+ static isReconstructable(value) {
806
+ return _hasChronosProperties(value);
807
+ }
808
+ static reconstruct(value) {
809
+ if (!_hasChronosProperties(value)) {
810
+ throw new TypeError('Invalid input for reconstruction!');
811
+ }
812
+ const { native, origin, utcOffset, timeZoneName, timeZoneId, $tzTracker } = value;
813
+ const offsetMins = extractMinutesFromUTC(utcOffset);
814
+ const instance = new _a(native);
815
+ const diffMins = instance.getTimeZoneOffsetMinutes() - offsetMins;
816
+ const target = instance.utcOffset === utcOffset ? instance : instance.add(-diffMins, 'minute');
817
+ return target.#withOrigin(origin, utcOffset, timeZoneName, timeZoneId, $tzTracker);
818
+ }
807
819
  static use(plugin) {
808
820
  if (!_a.#plugins.has(plugin)) {
809
821
  _a.#plugins.add(plugin);
@@ -1,6 +1,9 @@
1
+ import { isDate, isObjectWithKeys, isValidArray } from '../guards/non-primitives.js';
2
+ import { isNonEmptyString, isString } from '../guards/primitives.js';
3
+ import { isDateString } from '../guards/specials.js';
1
4
  import { getOrdinal } from '../number/utilities.js';
2
5
  import { BN_MONTH_TABLES, BN_SEASONS, BN_YEAR_OFFSET, DAYS, MONTHS, MS_PER_DAY, SORTED_TIME_FORMATS, } from './constants.js';
3
- import { isLeapYear } from './guards.js';
6
+ import { isLeapYear, isValidUTCOffset } from './guards.js';
4
7
  export function _formatDateCore(format, dateComponents) {
5
8
  const tokenRegex = new RegExp(`^(${SORTED_TIME_FORMATS.join('|')})`);
6
9
  let result = '';
@@ -130,3 +133,20 @@ export function _padZero(value, length = 2) {
130
133
  export function _padShunno(str, length = 2) {
131
134
  return str.padStart(length, '০');
132
135
  }
136
+ export function _dateArgsToDate(value) {
137
+ return isDate(value) ? value : (new Date(isString(value) ? value.replace(/['"]/g, '') : (value ?? Date.now())));
138
+ }
139
+ export function _hasChronosProperties(value) {
140
+ return (isObjectWithKeys(value, [
141
+ 'origin',
142
+ 'native',
143
+ 'utcOffset',
144
+ 'timeZoneName',
145
+ 'timeZoneId',
146
+ ]) &&
147
+ isNonEmptyString(value.origin) &&
148
+ (isDate(value.native) || isDateString(value.native)) &&
149
+ isValidUTCOffset(value.utcOffset) &&
150
+ isNonEmptyString(value.timeZoneName) &&
151
+ (isNonEmptyString(value.timeZoneId) || isValidArray(value.timeZoneId)));
152
+ }
@@ -1,6 +1,6 @@
1
- import { isString } from '../guards/primitives.js';
1
+ import { isObject } from '../guards/non-primitives.js';
2
2
  import { isValidUTCOffset } from './guards.js';
3
- import { _formatDate, _gmtToUtcOffset, _normalizeOffset, _resolveNativeTzName, } from './helpers.js';
3
+ import { _dateArgsToDate, _formatDate, _gmtToUtcOffset, _normalizeOffset, _resolveNativeTzName, } from './helpers.js';
4
4
  import { NATIVE_TZ_IDS } from './timezone.js';
5
5
  export function extractHourMinute(time) {
6
6
  const [hour, minute] = time.split(':').map(Number);
@@ -62,7 +62,7 @@ export function getTimeZoneIds(offset) {
62
62
  }
63
63
  export function formatDate(options) {
64
64
  const { date = new Date(), format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false, } = options ?? {};
65
- const $date = date instanceof Date ? date : (new Date(isString(date) ? date.replace(/['"]/g, '') : date));
65
+ const $date = _dateArgsToDate(date);
66
66
  if (isNaN($date.getTime())) {
67
67
  return 'Invalid Date!';
68
68
  }
@@ -77,3 +77,29 @@ export function formatTimePart(time, format) {
77
77
  const timeWithDate = `${formatDate({ format: 'YYYY-MM-DD' })}T${_normalizeOffset(time)}`;
78
78
  return formatDate({ date: timeWithDate, format: format || 'hh:mm:ss a' });
79
79
  }
80
+ export function getTimestamp(args, format) {
81
+ let $value;
82
+ let $format;
83
+ const _isTsOptions = (opt) => {
84
+ return isObject(opt) && ('value' in opt || 'format' in opt);
85
+ };
86
+ if (_isTsOptions(args)) {
87
+ $value = args.value || new Date();
88
+ $format = args.format || 'utc';
89
+ }
90
+ else {
91
+ $value = args || new Date();
92
+ $format = format || 'utc';
93
+ }
94
+ let date = _dateArgsToDate($value);
95
+ if (isNaN(date.getTime())) {
96
+ date = new Date();
97
+ }
98
+ if ($format === 'local') {
99
+ const offsetMins = date.getTimezoneOffset();
100
+ const localDate = new Date(date.getTime() - offsetMins * 60000);
101
+ const offset = formatUTCOffset(-offsetMins).slice(3);
102
+ return localDate.toISOString().replace('Z', offset);
103
+ }
104
+ return date.toISOString();
105
+ }
@@ -31,8 +31,13 @@ export function uuid(options) {
31
31
  }
32
32
  case 'v4': {
33
33
  const bytes = new Uint8Array(16);
34
- for (let i = 0; i < 16; i++) {
35
- bytes[i] = Math.floor(Math.random() * 256);
34
+ if (crypto.getRandomValues) {
35
+ crypto.getRandomValues(bytes);
36
+ }
37
+ else {
38
+ for (let i = 0; i < 16; i++) {
39
+ bytes[i] = Math.floor(Math.random() * 256);
40
+ }
36
41
  }
37
42
  let hex = '';
38
43
  for (let i = 0; i < 16; i++) {
@@ -76,8 +81,13 @@ export function uuid(options) {
76
81
  bytes[i] = Number(temp & 0xffn);
77
82
  temp >>= 8n;
78
83
  }
79
- for (let i = 6; i < 16; i++) {
80
- bytes[i] = Math.floor(Math.random() * 256);
84
+ if (crypto.getRandomValues) {
85
+ crypto.getRandomValues(bytes);
86
+ }
87
+ else {
88
+ for (let i = 6; i < 16; i++) {
89
+ bytes[i] = Math.floor(Math.random() * 256);
90
+ }
81
91
  }
82
92
  let hex = '';
83
93
  for (let i = 0; i < 16; i++) {
package/dist/esm/index.js CHANGED
@@ -30,7 +30,7 @@ export { BanglaCalendar, BnCalendar, Bongabdo } from './date/BanglaCalendar.js';
30
30
  export { Chronos, Chronus } from './date/Chronos.js';
31
31
  export { INTERNALS } from './date/constants.js';
32
32
  export { chronos, chronosjs, chronosts, chronus, chronusjs, chronusts, } from './date/chronos-fn.js';
33
- export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatTimePart, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, convertMinutesToTime as getHourMinutesFromMinutes, extractMinutesFromUTC as getMinutesFromUTC, getNativeTimeZoneId, convertMinutesToTime as getTimeFromMinutes, extractTimeFromUTC as getTimeStringFromUTC, getTimeZoneDetails, getTimeZoneIds, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils.js';
33
+ export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatTimePart, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, getTimestamp, convertMinutesToTime as getHourMinutesFromMinutes, extractMinutesFromUTC as getMinutesFromUTC, getNativeTimeZoneId, convertMinutesToTime as getTimeFromMinutes, extractTimeFromUTC as getTimeStringFromUTC, getTimeZoneDetails, getTimeZoneIds, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils.js';
34
34
  export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics.js';
35
35
  export { averageByField, averageByField as avgByField, groupAndAverageByField, groupAndAverageByField as groupAndAvgByField, groupAndSumByField, sumByField, sumFieldDifference, sumFieldDifference as totalDeltaByField, } from './array/calc.js';
36
36
  export { Finder } from './array/Finder.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.28.66",
3
+ "version": "4.28.71",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -46,21 +46,21 @@
46
46
  "devDependencies": {
47
47
  "@eslint/js": "^9.39.2",
48
48
  "@types/jest": "^30.0.0",
49
- "@types/node": "^25.0.9",
50
- "@typescript-eslint/eslint-plugin": "^8.53.1",
51
- "@typescript-eslint/parser": "^8.53.1",
49
+ "@types/node": "^25.2.1",
50
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
51
+ "@typescript-eslint/parser": "^8.54.0",
52
52
  "eslint": "^9.39.2",
53
53
  "eslint-config-prettier": "^10.1.8",
54
54
  "eslint-plugin-prettier": "^5.5.5",
55
- "globals": "^17.0.0",
55
+ "globals": "^17.3.0",
56
56
  "husky": "^9.1.7",
57
57
  "jest": "^30.2.0",
58
58
  "lint-staged": "^16.2.7",
59
59
  "nhb-scripts": "^1.9.2",
60
- "prettier": "^3.8.0",
60
+ "prettier": "^3.8.1",
61
61
  "ts-jest": "^29.4.6",
62
62
  "typescript": "^5.9.3",
63
- "typescript-eslint": "^8.53.1"
63
+ "typescript-eslint": "^8.54.0"
64
64
  },
65
65
  "keywords": [
66
66
  "toolbox",