@nymphjs/guid 1.0.0-beta.45 → 1.0.0-beta.47

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
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-beta.47](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.46...v1.0.0-beta.47) (2023-11-10)
7
+
8
+ **Note:** Version bump only for package @nymphjs/guid
9
+
10
+ # [1.0.0-beta.46](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.45...v1.0.0-beta.46) (2023-08-29)
11
+
12
+ **Note:** Version bump only for package @nymphjs/guid
13
+
6
14
  # [1.0.0-beta.45](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.44...v1.0.0-beta.45) (2023-07-17)
7
15
 
8
16
  **Note:** Version bump only for package @nymphjs/guid
package/dist/index.js CHANGED
@@ -1,28 +1,28 @@
1
1
  'use strict';
2
2
 
3
- var crypto = require('crypto');
3
+ var node_crypto = require('node:crypto');
4
4
 
5
5
  const urlAlphabet =
6
6
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
7
7
 
8
8
  const POOL_SIZE_MULTIPLIER = 128;
9
9
  let pool, poolOffset;
10
- let fillPool = bytes => {
10
+ function fillPool(bytes) {
11
11
  if (!pool || pool.length < bytes) {
12
12
  pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
13
- crypto.randomFillSync(pool);
13
+ node_crypto.webcrypto.getRandomValues(pool);
14
14
  poolOffset = 0;
15
15
  } else if (poolOffset + bytes > pool.length) {
16
- crypto.randomFillSync(pool);
16
+ node_crypto.webcrypto.getRandomValues(pool);
17
17
  poolOffset = 0;
18
18
  }
19
19
  poolOffset += bytes;
20
- };
21
- let random = bytes => {
20
+ }
21
+ function random(bytes) {
22
22
  fillPool((bytes -= 0));
23
23
  return pool.subarray(poolOffset - bytes, poolOffset)
24
- };
25
- let customRandom = (alphabet, defaultSize, getRandom) => {
24
+ }
25
+ function customRandom(alphabet, defaultSize, getRandom) {
26
26
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1;
27
27
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length);
28
28
  return (size = defaultSize) => {
@@ -36,17 +36,18 @@ let customRandom = (alphabet, defaultSize, getRandom) => {
36
36
  }
37
37
  }
38
38
  }
39
- };
40
- let customAlphabet = (alphabet, size = 21) =>
41
- customRandom(alphabet, size, random);
42
- let nanoid = (size = 21) => {
39
+ }
40
+ function customAlphabet(alphabet, size = 21) {
41
+ return customRandom(alphabet, size, random)
42
+ }
43
+ function nanoid(size = 21) {
43
44
  fillPool((size -= 0));
44
45
  let id = '';
45
46
  for (let i = poolOffset - size; i < poolOffset; i++) {
46
47
  id += urlAlphabet[pool[i] & 63];
47
48
  }
48
49
  return id
49
- };
50
+ }
50
51
 
51
52
  // these aren't really private, but nor are they really useful to document
52
53
 
@@ -739,7 +740,7 @@ function intlConfigString(localeStr, numberingSystem, outputCalendar) {
739
740
  function mapMonths(f) {
740
741
  const ms = [];
741
742
  for (let i = 1; i <= 12; i++) {
742
- const dt = DateTime.utc(2016, i, 1);
743
+ const dt = DateTime.utc(2009, i, 1);
743
744
  ms.push(f(dt));
744
745
  }
745
746
  return ms;
@@ -754,8 +755,8 @@ function mapWeekdays(f) {
754
755
  return ms;
755
756
  }
756
757
 
757
- function listStuff(loc, length, defaultOK, englishFn, intlFn) {
758
- const mode = loc.listingMode(defaultOK);
758
+ function listStuff(loc, length, englishFn, intlFn) {
759
+ const mode = loc.listingMode();
759
760
 
760
761
  if (mode === "error") {
761
762
  return null;
@@ -1007,8 +1008,8 @@ class Locale {
1007
1008
  return this.clone({ ...alts, defaultToEN: false });
1008
1009
  }
1009
1010
 
1010
- months(length, format = false, defaultOK = true) {
1011
- return listStuff(this, length, defaultOK, months, () => {
1011
+ months(length, format = false) {
1012
+ return listStuff(this, length, months, () => {
1012
1013
  const intl = format ? { month: length, day: "numeric" } : { month: length },
1013
1014
  formatStr = format ? "format" : "standalone";
1014
1015
  if (!this.monthsCache[formatStr][length]) {
@@ -1018,8 +1019,8 @@ class Locale {
1018
1019
  });
1019
1020
  }
1020
1021
 
1021
- weekdays(length, format = false, defaultOK = true) {
1022
- return listStuff(this, length, defaultOK, weekdays, () => {
1022
+ weekdays(length, format = false) {
1023
+ return listStuff(this, length, weekdays, () => {
1023
1024
  const intl = format
1024
1025
  ? { weekday: length, year: "numeric", month: "long", day: "numeric" }
1025
1026
  : { weekday: length },
@@ -1033,11 +1034,10 @@ class Locale {
1033
1034
  });
1034
1035
  }
1035
1036
 
1036
- meridiems(defaultOK = true) {
1037
+ meridiems() {
1037
1038
  return listStuff(
1038
1039
  this,
1039
1040
  undefined,
1040
- defaultOK,
1041
1041
  () => meridiems,
1042
1042
  () => {
1043
1043
  // In theory there could be aribitrary day periods. We're gonna assume there are exactly two
@@ -1054,8 +1054,8 @@ class Locale {
1054
1054
  );
1055
1055
  }
1056
1056
 
1057
- eras(length, defaultOK = true) {
1058
- return listStuff(this, length, defaultOK, eras, () => {
1057
+ eras(length) {
1058
+ return listStuff(this, length, eras, () => {
1059
1059
  const intl = { era: length };
1060
1060
 
1061
1061
  // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates
@@ -1282,7 +1282,7 @@ function normalizeZone(input, defaultZone) {
1282
1282
  else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input);
1283
1283
  } else if (isNumber(input)) {
1284
1284
  return FixedOffsetZone.instance(input);
1285
- } else if (typeof input === "object" && input.offset && typeof input.offset === "number") {
1285
+ } else if (typeof input === "object" && "offset" in input && typeof input.offset === "function") {
1286
1286
  // This is dumb, but the instanceof check above doesn't seem to really work
1287
1287
  // so we're duck checking it
1288
1288
  return input;
@@ -1399,10 +1399,10 @@ class Settings {
1399
1399
  /**
1400
1400
  * Set the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
1401
1401
  * @type {number}
1402
- * @example Settings.twoDigitCutoffYear = 0 // cut-off year is 0, so all 'yy' are interpretted as current century
1402
+ * @example Settings.twoDigitCutoffYear = 0 // cut-off year is 0, so all 'yy' are interpreted as current century
1403
1403
  * @example Settings.twoDigitCutoffYear = 50 // '49' -> 1949; '50' -> 2050
1404
- * @example Settings.twoDigitCutoffYear = 1950 // interpretted as 50
1405
- * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpretted as 50
1404
+ * @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50
1405
+ * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50
1406
1406
  */
1407
1407
  static set twoDigitCutoffYear(cutoffYear) {
1408
1408
  twoDigitCutoffYear = cutoffYear % 100;
@@ -1585,7 +1585,7 @@ function daysInMonth(year, month) {
1585
1585
  }
1586
1586
  }
1587
1587
 
1588
- // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
1588
+ // convert a calendar object to a local timestamp (epoch, but with the offset baked in)
1589
1589
  function objToLocalTS(obj) {
1590
1590
  let d = Date.UTC(
1591
1591
  obj.year,
@@ -1965,24 +1965,25 @@ class Formatter {
1965
1965
  return df.format();
1966
1966
  }
1967
1967
 
1968
- formatDateTime(dt, opts = {}) {
1969
- const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
1970
- return df.format();
1968
+ dtFormatter(dt, opts = {}) {
1969
+ return this.loc.dtFormatter(dt, { ...this.opts, ...opts });
1970
+ }
1971
+
1972
+ formatDateTime(dt, opts) {
1973
+ return this.dtFormatter(dt, opts).format();
1971
1974
  }
1972
1975
 
1973
- formatDateTimeParts(dt, opts = {}) {
1974
- const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
1975
- return df.formatToParts();
1976
+ formatDateTimeParts(dt, opts) {
1977
+ return this.dtFormatter(dt, opts).formatToParts();
1976
1978
  }
1977
1979
 
1978
- formatInterval(interval, opts = {}) {
1979
- const df = this.loc.dtFormatter(interval.start, { ...this.opts, ...opts });
1980
+ formatInterval(interval, opts) {
1981
+ const df = this.dtFormatter(interval.start, opts);
1980
1982
  return df.dtf.formatRange(interval.start.toJSDate(), interval.end.toJSDate());
1981
1983
  }
1982
1984
 
1983
- resolvedOptions(dt, opts = {}) {
1984
- const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
1985
- return df.resolvedOptions();
1985
+ resolvedOptions(dt, opts) {
1986
+ return this.dtFormatter(dt, opts).resolvedOptions();
1986
1987
  }
1987
1988
 
1988
1989
  num(n, p = 0) {
@@ -2037,7 +2038,7 @@ class Formatter {
2037
2038
  era = (length) =>
2038
2039
  knownEnglish ? eraForDateTime(dt, length) : string({ era: length }, "era"),
2039
2040
  tokenToString = (token) => {
2040
- // Where possible: http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles
2041
+ // Where possible: https://cldr.unicode.org/translation/date-time/date-time-symbols
2041
2042
  switch (token) {
2042
2043
  // ms
2043
2044
  case "S":
@@ -2714,28 +2715,61 @@ function clone$1(dur, alts, clear = false) {
2714
2715
  return new Duration(conf);
2715
2716
  }
2716
2717
 
2717
- function antiTrunc(n) {
2718
- return n < 0 ? Math.floor(n) : Math.ceil(n);
2719
- }
2720
-
2721
- // NB: mutates parameters
2722
- function convert(matrix, fromMap, fromUnit, toMap, toUnit) {
2723
- const conv = matrix[toUnit][fromUnit],
2724
- raw = fromMap[fromUnit] / conv,
2725
- sameSign = Math.sign(raw) === Math.sign(toMap[toUnit]),
2726
- // ok, so this is wild, but see the matrix in the tests
2727
- added =
2728
- !sameSign && toMap[toUnit] !== 0 && Math.abs(raw) <= 1 ? antiTrunc(raw) : Math.trunc(raw);
2729
- toMap[toUnit] += added;
2730
- fromMap[fromUnit] -= added * conv;
2718
+ function durationToMillis(matrix, vals) {
2719
+ let sum = vals.milliseconds ?? 0;
2720
+ for (const unit of reverseUnits.slice(1)) {
2721
+ if (vals[unit]) {
2722
+ sum += vals[unit] * matrix[unit]["milliseconds"];
2723
+ }
2724
+ }
2725
+ return sum;
2731
2726
  }
2732
2727
 
2733
2728
  // NB: mutates parameters
2734
2729
  function normalizeValues(matrix, vals) {
2735
- reverseUnits.reduce((previous, current) => {
2730
+ // the logic below assumes the overall value of the duration is positive
2731
+ // if this is not the case, factor is used to make it so
2732
+ const factor = durationToMillis(matrix, vals) < 0 ? -1 : 1;
2733
+
2734
+ orderedUnits$1.reduceRight((previous, current) => {
2735
+ if (!isUndefined(vals[current])) {
2736
+ if (previous) {
2737
+ const previousVal = vals[previous] * factor;
2738
+ const conv = matrix[current][previous];
2739
+
2740
+ // if (previousVal < 0):
2741
+ // lower order unit is negative (e.g. { years: 2, days: -2 })
2742
+ // normalize this by reducing the higher order unit by the appropriate amount
2743
+ // and increasing the lower order unit
2744
+ // this can never make the higher order unit negative, because this function only operates
2745
+ // on positive durations, so the amount of time represented by the lower order unit cannot
2746
+ // be larger than the higher order unit
2747
+ // else:
2748
+ // lower order unit is positive (e.g. { years: 2, days: 450 } or { years: -2, days: 450 })
2749
+ // in this case we attempt to convert as much as possible from the lower order unit into
2750
+ // the higher order one
2751
+ //
2752
+ // Math.floor takes care of both of these cases, rounding away from 0
2753
+ // if previousVal < 0 it makes the absolute value larger
2754
+ // if previousVal >= it makes the absolute value smaller
2755
+ const rollUp = Math.floor(previousVal / conv);
2756
+ vals[current] += rollUp * factor;
2757
+ vals[previous] -= rollUp * conv * factor;
2758
+ }
2759
+ return current;
2760
+ } else {
2761
+ return previous;
2762
+ }
2763
+ }, null);
2764
+
2765
+ // try to convert any decimals into smaller units if possible
2766
+ // for example for { years: 2.5, days: 0, seconds: 0 } we want to get { years: 2, days: 182, hours: 12 }
2767
+ orderedUnits$1.reduce((previous, current) => {
2736
2768
  if (!isUndefined(vals[current])) {
2737
2769
  if (previous) {
2738
- convert(matrix, vals, previous, vals, current);
2770
+ const fraction = vals[previous] % 1;
2771
+ vals[previous] -= fraction;
2772
+ vals[current] += fraction * matrix[previous][current];
2739
2773
  }
2740
2774
  return current;
2741
2775
  } else {
@@ -3051,6 +3085,8 @@ class Duration {
3051
3085
  * ```
3052
3086
  */
3053
3087
  toHuman(opts = {}) {
3088
+ if (!this.isValid) return INVALID$2;
3089
+
3054
3090
  const l = orderedUnits$1
3055
3091
  .map((unit) => {
3056
3092
  const val = this.values[unit];
@@ -3137,26 +3173,11 @@ class Duration {
3137
3173
  includePrefix: false,
3138
3174
  format: "extended",
3139
3175
  ...opts,
3176
+ includeOffset: false,
3140
3177
  };
3141
3178
 
3142
- const value = this.shiftTo("hours", "minutes", "seconds", "milliseconds");
3143
-
3144
- let fmt = opts.format === "basic" ? "hhmm" : "hh:mm";
3145
-
3146
- if (!opts.suppressSeconds || value.seconds !== 0 || value.milliseconds !== 0) {
3147
- fmt += opts.format === "basic" ? "ss" : ":ss";
3148
- if (!opts.suppressMilliseconds || value.milliseconds !== 0) {
3149
- fmt += ".SSS";
3150
- }
3151
- }
3152
-
3153
- let str = value.toFormat(fmt);
3154
-
3155
- if (opts.includePrefix) {
3156
- str = "T" + str;
3157
- }
3158
-
3159
- return str;
3179
+ const dateTime = DateTime.fromMillis(millis, { zone: "UTC" });
3180
+ return dateTime.toISOTime(opts);
3160
3181
  }
3161
3182
 
3162
3183
  /**
@@ -3180,7 +3201,9 @@ class Duration {
3180
3201
  * @return {number}
3181
3202
  */
3182
3203
  toMillis() {
3183
- return this.as("milliseconds");
3204
+ if (!this.isValid) return NaN;
3205
+
3206
+ return durationToMillis(this.matrix, this.values);
3184
3207
  }
3185
3208
 
3186
3209
  /**
@@ -3290,8 +3313,17 @@ class Duration {
3290
3313
 
3291
3314
  /**
3292
3315
  * Reduce this Duration to its canonical representation in its current units.
3316
+ * Assuming the overall value of the Duration is positive, this means:
3317
+ * - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
3318
+ * - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
3319
+ * the overall value would be negative, see second example)
3320
+ * - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
3321
+ *
3322
+ * If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
3293
3323
  * @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 }
3324
+ * @example Duration.fromObject({ days: 5000 }).normalize().toObject() //=> { days: 5000 }
3294
3325
  * @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 }
3326
+ * @example Duration.fromObject({ years: 2.5, days: 0, hours: 0 }).normalize().toObject() //=> { years: 2, days: 182, hours: 12 }
3295
3327
  * @return {Duration}
3296
3328
  */
3297
3329
  normalize() {
@@ -3348,16 +3380,12 @@ class Duration {
3348
3380
  own += vals[k];
3349
3381
  }
3350
3382
 
3383
+ // only keep the integer part for now in the hopes of putting any decimal part
3384
+ // into a smaller unit later
3351
3385
  const i = Math.trunc(own);
3352
3386
  built[k] = i;
3353
3387
  accumulated[k] = (own * 1000 - i * 1000) / 1000;
3354
3388
 
3355
- // plus anything further down the chain that should be rolled up in to this
3356
- for (const down in vals) {
3357
- if (orderedUnits$1.indexOf(down) > orderedUnits$1.indexOf(k)) {
3358
- convert(this.matrix, vals, down, built, k);
3359
- }
3360
- }
3361
3389
  // otherwise, keep it in the wings to boil it later
3362
3390
  } else if (isNumber(vals[k])) {
3363
3391
  accumulated[k] = vals[k];
@@ -3373,7 +3401,8 @@ class Duration {
3373
3401
  }
3374
3402
  }
3375
3403
 
3376
- return clone$1(this, { values: built }, true).normalize();
3404
+ normalizeValues(this.matrix, built);
3405
+ return clone$1(this, { values: built }, true);
3377
3406
  }
3378
3407
 
3379
3408
  /**
@@ -4353,6 +4382,14 @@ function highOrderDiffs(cursor, later, units) {
4353
4382
  const earlier = cursor;
4354
4383
  let lowestOrder, highWater;
4355
4384
 
4385
+ /* This loop tries to diff using larger units first.
4386
+ If we overshoot, we backtrack and try the next smaller unit.
4387
+ "cursor" starts out at the earlier timestamp and moves closer and closer to "later"
4388
+ as we use smaller and smaller units.
4389
+ highWater keeps track of where we would be if we added one more of the smallest unit,
4390
+ this is used later to potentially convert any difference smaller than the smallest higher order unit
4391
+ into a fraction of that smallest higher order unit
4392
+ */
4356
4393
  for (const [unit, differ] of differs) {
4357
4394
  if (units.indexOf(unit) >= 0) {
4358
4395
  lowestOrder = unit;
@@ -4361,8 +4398,20 @@ function highOrderDiffs(cursor, later, units) {
4361
4398
  highWater = earlier.plus(results);
4362
4399
 
4363
4400
  if (highWater > later) {
4401
+ // we overshot the end point, backtrack cursor by 1
4364
4402
  results[unit]--;
4365
4403
  cursor = earlier.plus(results);
4404
+
4405
+ // if we are still overshooting now, we need to backtrack again
4406
+ // this happens in certain situations when diffing times in different zones,
4407
+ // because this calculation ignores time zones
4408
+ if (cursor > later) {
4409
+ // keep the "overshot by 1" around as highWater
4410
+ highWater = cursor;
4411
+ // backtrack cursor by 1
4412
+ results[unit]--;
4413
+ cursor = earlier.plus(results);
4414
+ }
4366
4415
  } else {
4367
4416
  cursor = highWater;
4368
4417
  }
@@ -4525,6 +4574,10 @@ function escapeToken(value) {
4525
4574
  return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
4526
4575
  }
4527
4576
 
4577
+ /**
4578
+ * @param token
4579
+ * @param {Locale} loc
4580
+ */
4528
4581
  function unitForToken(token, loc) {
4529
4582
  const one = digitRegex(loc),
4530
4583
  two = digitRegex(loc, "{2}"),
@@ -4545,9 +4598,9 @@ function unitForToken(token, loc) {
4545
4598
  switch (t.val) {
4546
4599
  // era
4547
4600
  case "G":
4548
- return oneOf(loc.eras("short", false), 0);
4601
+ return oneOf(loc.eras("short"), 0);
4549
4602
  case "GG":
4550
- return oneOf(loc.eras("long", false), 0);
4603
+ return oneOf(loc.eras("long"), 0);
4551
4604
  // years
4552
4605
  case "y":
4553
4606
  return intUnit(oneToSix);
@@ -4565,17 +4618,17 @@ function unitForToken(token, loc) {
4565
4618
  case "MM":
4566
4619
  return intUnit(two);
4567
4620
  case "MMM":
4568
- return oneOf(loc.months("short", true, false), 1);
4621
+ return oneOf(loc.months("short", true), 1);
4569
4622
  case "MMMM":
4570
- return oneOf(loc.months("long", true, false), 1);
4623
+ return oneOf(loc.months("long", true), 1);
4571
4624
  case "L":
4572
4625
  return intUnit(oneOrTwo);
4573
4626
  case "LL":
4574
4627
  return intUnit(two);
4575
4628
  case "LLL":
4576
- return oneOf(loc.months("short", false, false), 1);
4629
+ return oneOf(loc.months("short", false), 1);
4577
4630
  case "LLLL":
4578
- return oneOf(loc.months("long", false, false), 1);
4631
+ return oneOf(loc.months("long", false), 1);
4579
4632
  // dates
4580
4633
  case "d":
4581
4634
  return intUnit(oneOrTwo);
@@ -4635,13 +4688,13 @@ function unitForToken(token, loc) {
4635
4688
  case "c":
4636
4689
  return intUnit(one);
4637
4690
  case "EEE":
4638
- return oneOf(loc.weekdays("short", false, false), 1);
4691
+ return oneOf(loc.weekdays("short", false), 1);
4639
4692
  case "EEEE":
4640
- return oneOf(loc.weekdays("long", false, false), 1);
4693
+ return oneOf(loc.weekdays("long", false), 1);
4641
4694
  case "ccc":
4642
- return oneOf(loc.weekdays("short", true, false), 1);
4695
+ return oneOf(loc.weekdays("short", true), 1);
4643
4696
  case "cccc":
4644
- return oneOf(loc.weekdays("long", true, false), 1);
4697
+ return oneOf(loc.weekdays("long", true), 1);
4645
4698
  // offset/zone
4646
4699
  case "Z":
4647
4700
  case "ZZ":
@@ -4691,10 +4744,14 @@ const partTypeStyleToTokenVal = {
4691
4744
  },
4692
4745
  dayperiod: "a",
4693
4746
  dayPeriod: "a",
4694
- hour: {
4747
+ hour12: {
4695
4748
  numeric: "h",
4696
4749
  "2-digit": "hh",
4697
4750
  },
4751
+ hour24: {
4752
+ numeric: "H",
4753
+ "2-digit": "HH",
4754
+ },
4698
4755
  minute: {
4699
4756
  numeric: "m",
4700
4757
  "2-digit": "mm",
@@ -4709,7 +4766,7 @@ const partTypeStyleToTokenVal = {
4709
4766
  },
4710
4767
  };
4711
4768
 
4712
- function tokenForPart(part, formatOpts) {
4769
+ function tokenForPart(part, formatOpts, resolvedOpts) {
4713
4770
  const { type, value } = part;
4714
4771
 
4715
4772
  if (type === "literal") {
@@ -4722,7 +4779,26 @@ function tokenForPart(part, formatOpts) {
4722
4779
 
4723
4780
  const style = formatOpts[type];
4724
4781
 
4725
- let val = partTypeStyleToTokenVal[type];
4782
+ // The user might have explicitly specified hour12 or hourCycle
4783
+ // if so, respect their decision
4784
+ // if not, refer back to the resolvedOpts, which are based on the locale
4785
+ let actualType = type;
4786
+ if (type === "hour") {
4787
+ if (formatOpts.hour12 != null) {
4788
+ actualType = formatOpts.hour12 ? "hour12" : "hour24";
4789
+ } else if (formatOpts.hourCycle != null) {
4790
+ if (formatOpts.hourCycle === "h11" || formatOpts.hourCycle === "h12") {
4791
+ actualType = "hour12";
4792
+ } else {
4793
+ actualType = "hour24";
4794
+ }
4795
+ } else {
4796
+ // tokens only differentiate between 24 hours or not,
4797
+ // so we do not need to check hourCycle here, which is less supported anyways
4798
+ actualType = resolvedOpts.hour12 ? "hour12" : "hour24";
4799
+ }
4800
+ }
4801
+ let val = partTypeStyleToTokenVal[actualType];
4726
4802
  if (typeof val === "object") {
4727
4803
  val = val[style];
4728
4804
  }
@@ -4911,8 +4987,10 @@ function formatOptsToTokens(formatOpts, locale) {
4911
4987
  }
4912
4988
 
4913
4989
  const formatter = Formatter.create(locale, formatOpts);
4914
- const parts = formatter.formatDateTimeParts(getDummyDateTime());
4915
- return parts.map((p) => tokenForPart(p, formatOpts));
4990
+ const df = formatter.dtFormatter(getDummyDateTime());
4991
+ const parts = df.formatToParts();
4992
+ const resolvedOpts = df.resolvedOptions();
4993
+ return parts.map((p) => tokenForPart(p, formatOpts, resolvedOpts));
4916
4994
  }
4917
4995
 
4918
4996
  const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
@@ -5242,14 +5320,14 @@ function toISOTime(
5242
5320
  if (extended) {
5243
5321
  c += ":";
5244
5322
  c += padStart(o.c.minute);
5245
- if (o.c.second !== 0 || !suppressSeconds) {
5323
+ if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
5246
5324
  c += ":";
5247
5325
  }
5248
5326
  } else {
5249
5327
  c += padStart(o.c.minute);
5250
5328
  }
5251
5329
 
5252
- if (o.c.second !== 0 || !suppressSeconds) {
5330
+ if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
5253
5331
  c += padStart(o.c.second);
5254
5332
 
5255
5333
  if (o.c.millisecond !== 0 || !suppressMilliseconds) {
@@ -5912,7 +5990,7 @@ class DateTime {
5912
5990
 
5913
5991
  /**
5914
5992
  * Create an invalid DateTime.
5915
- * @param {DateTime} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent
5993
+ * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent.
5916
5994
  * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
5917
5995
  * @return {DateTime}
5918
5996
  */
@@ -6261,6 +6339,43 @@ class DateTime {
6261
6339
  }
6262
6340
  }
6263
6341
 
6342
+ /**
6343
+ * Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC
6344
+ * in this DateTime's zone. During DST changes local time can be ambiguous, for example
6345
+ * `2023-10-29T02:30:00` in `Europe/Berlin` can have offset `+01:00` or `+02:00`.
6346
+ * This method will return both possible DateTimes if this DateTime's local time is ambiguous.
6347
+ * @returns {DateTime[]}
6348
+ */
6349
+ getPossibleOffsets() {
6350
+ if (!this.isValid || this.isOffsetFixed) {
6351
+ return [this];
6352
+ }
6353
+ const dayMs = 86400000;
6354
+ const minuteMs = 60000;
6355
+ const localTS = objToLocalTS(this.c);
6356
+ const oEarlier = this.zone.offset(localTS - dayMs);
6357
+ const oLater = this.zone.offset(localTS + dayMs);
6358
+
6359
+ const o1 = this.zone.offset(localTS - oEarlier * minuteMs);
6360
+ const o2 = this.zone.offset(localTS - oLater * minuteMs);
6361
+ if (o1 === o2) {
6362
+ return [this];
6363
+ }
6364
+ const ts1 = localTS - o1 * minuteMs;
6365
+ const ts2 = localTS - o2 * minuteMs;
6366
+ const c1 = tsToObj(ts1, o1);
6367
+ const c2 = tsToObj(ts2, o2);
6368
+ if (
6369
+ c1.hour === c2.hour &&
6370
+ c1.minute === c2.minute &&
6371
+ c1.second === c2.second &&
6372
+ c1.millisecond === c2.millisecond
6373
+ ) {
6374
+ return [clone(this, { ts: ts1 }), clone(this, { ts: ts2 })];
6375
+ }
6376
+ return [this];
6377
+ }
6378
+
6264
6379
  /**
6265
6380
  * Returns true if this DateTime is in a leap year, false otherwise
6266
6381
  * @example DateTime.local(2016).isInLeapYear //=> true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nymphjs/guid",
3
- "version": "1.0.0-beta.45",
3
+ "version": "1.0.0-beta.47",
4
4
  "description": "Nymph.js - GUID and Unique Code Generators",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -32,23 +32,23 @@
32
32
  },
33
33
  "license": "Apache-2.0",
34
34
  "devDependencies": {
35
- "@rollup/plugin-commonjs": "^25.0.1",
36
- "@rollup/plugin-node-resolve": "^15.1.0",
37
- "@rollup/plugin-typescript": "^11.1.1",
38
- "@tsconfig/recommended": "^1.0.2",
39
- "@types/jest": "^29.5.2",
40
- "@types/luxon": "^3.3.0",
41
- "@types/nanoid-dictionary": "^4.2.0",
42
- "@types/sha1": "^1.1.3",
43
- "jest": "^29.5.0",
44
- "luxon": "^3.3.0",
45
- "nanoid": "^4.0.2",
35
+ "@rollup/plugin-commonjs": "^25.0.7",
36
+ "@rollup/plugin-node-resolve": "^15.2.3",
37
+ "@rollup/plugin-typescript": "^11.1.5",
38
+ "@tsconfig/recommended": "^1.0.3",
39
+ "@types/jest": "^29.5.8",
40
+ "@types/luxon": "^3.3.4",
41
+ "@types/nanoid-dictionary": "^4.2.3",
42
+ "@types/sha1": "^1.1.5",
43
+ "jest": "^29.7.0",
44
+ "luxon": "^3.4.3",
45
+ "nanoid": "^5.0.3",
46
46
  "nanoid-dictionary": "^4.3.0",
47
- "rollup": "^3.25.1",
47
+ "rollup": "^4.3.0",
48
48
  "sha1": "^1.1.1",
49
- "ts-jest": "^29.1.0",
50
- "tslib": "^2.5.3",
51
- "typescript": "^5.1.3"
49
+ "ts-jest": "^29.1.1",
50
+ "tslib": "^2.6.2",
51
+ "typescript": "^5.2.2"
52
52
  },
53
- "gitHead": "54e7585f6b1cd6c920e47e01414dfc427eb73886"
53
+ "gitHead": "228f0d25911d1b98859f2acf8ace3d3f251c4882"
54
54
  }
package/src/index.ts CHANGED
@@ -8,13 +8,13 @@ const { nolookalikesSafe } = dictionary;
8
8
  const guidSuffix = customAlphabet('0123456789abcdef', 20);
9
9
  export function guid() {
10
10
  return `${sha1(
11
- `${DateTime.now().weekYear}${DateTime.now().weekNumber}`
11
+ `${DateTime.now().weekYear}${DateTime.now().weekNumber}`,
12
12
  ).slice(0, 4)}${guidSuffix()}`;
13
13
  }
14
14
 
15
15
  export const makeTableSuffix = customAlphabet(
16
16
  '0123456789abcdefghijklmnopqrstuvwxyz',
17
- 20
17
+ 20,
18
18
  );
19
19
 
20
20
  export const humanSecret = customAlphabet(nolookalikesSafe, 10);