@nymphjs/guid 1.0.0-beta.11 → 1.0.0-beta.12

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,12 @@
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.12](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2023-03-04)
7
+
8
+ ### Bug Fixes
9
+
10
+ - make sure all default exports are also named exports ([06da9a6](https://github.com/sciactive/nymphjs/commit/06da9a61d444860f70b7f5b95b824547d9880500))
11
+
6
12
  # [1.0.0-beta.11](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2023-02-27)
7
13
 
8
14
  **Note:** Version bump only for package @nymphjs/guid
package/dist/index.js CHANGED
@@ -816,9 +816,13 @@ class PolyNumberFormatter {
816
816
  class PolyDateFormatter {
817
817
  constructor(dt, intl, opts) {
818
818
  this.opts = opts;
819
+ this.originalZone = undefined;
819
820
 
820
821
  let z = undefined;
821
- if (dt.zone.isUniversal) {
822
+ if (this.opts.timeZone) {
823
+ // Don't apply any workarounds if a timeZone is explicitly provided in opts
824
+ this.dt = dt;
825
+ } else if (dt.zone.type === "fixed") {
822
826
  // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
823
827
  // That is why fixed-offset TZ is set to that unless it is:
824
828
  // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
@@ -831,25 +835,23 @@ class PolyDateFormatter {
831
835
  z = offsetZ;
832
836
  this.dt = dt;
833
837
  } else {
834
- // Not all fixed-offset zones like Etc/+4:30 are present in tzdata.
835
- // So we have to make do. Two cases:
836
- // 1. The format options tell us to show the zone. We can't do that, so the best
837
- // we can do is format the date in UTC.
838
- // 2. The format options don't tell us to show the zone. Then we can adjust them
839
- // the time and tell the formatter to show it to us in UTC, so that the time is right
840
- // and the bad zone doesn't show up.
838
+ // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
839
+ // we manually apply the offset and substitute the zone as needed.
841
840
  z = "UTC";
842
- if (opts.timeZoneName) {
843
- this.dt = dt;
844
- } else {
845
- this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000);
846
- }
841
+ this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
842
+ this.originalZone = dt.zone;
847
843
  }
848
844
  } else if (dt.zone.type === "system") {
849
845
  this.dt = dt;
850
- } else {
846
+ } else if (dt.zone.type === "iana") {
851
847
  this.dt = dt;
852
848
  z = dt.zone.name;
849
+ } else {
850
+ // Custom zones can have any offset / offsetName so we just manually
851
+ // apply the offset and substitute the zone as needed.
852
+ z = "UTC";
853
+ this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
854
+ this.originalZone = dt.zone;
853
855
  }
854
856
 
855
857
  const intlOpts = { ...this.opts };
@@ -858,11 +860,35 @@ class PolyDateFormatter {
858
860
  }
859
861
 
860
862
  format() {
863
+ if (this.originalZone) {
864
+ // If we have to substitute in the actual zone name, we have to use
865
+ // formatToParts so that the timezone can be replaced.
866
+ return this.formatToParts()
867
+ .map(({ value }) => value)
868
+ .join("");
869
+ }
861
870
  return this.dtf.format(this.dt.toJSDate());
862
871
  }
863
872
 
864
873
  formatToParts() {
865
- return this.dtf.formatToParts(this.dt.toJSDate());
874
+ const parts = this.dtf.formatToParts(this.dt.toJSDate());
875
+ if (this.originalZone) {
876
+ return parts.map((part) => {
877
+ if (part.type === "timeZoneName") {
878
+ const offsetName = this.originalZone.offsetName(this.dt.ts, {
879
+ locale: this.dt.locale,
880
+ format: this.opts.timeZoneName,
881
+ });
882
+ return {
883
+ ...part,
884
+ value: offsetName,
885
+ };
886
+ } else {
887
+ return part;
888
+ }
889
+ });
890
+ }
891
+ return parts;
866
892
  }
867
893
 
868
894
  resolvedOptions() {
@@ -1572,7 +1598,10 @@ function objToLocalTS(obj) {
1572
1598
  // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
1573
1599
  if (obj.year < 100 && obj.year >= 0) {
1574
1600
  d = new Date(d);
1575
- d.setUTCFullYear(d.getUTCFullYear() - 1900);
1601
+ // set the month and day again, this is necessary because year 2000 is a leap year, but year 100 is not
1602
+ // so if obj.year is in 99, but obj.day makes it roll over into year 100,
1603
+ // the calculations done by Date.UTC are using year 2000 - which is incorrect
1604
+ d.setUTCFullYear(obj.year, obj.month - 1, obj.day);
1576
1605
  }
1577
1606
  return +d;
1578
1607
  }
@@ -1880,6 +1909,9 @@ class Formatter {
1880
1909
  }
1881
1910
 
1882
1911
  static parseFormat(fmt) {
1912
+ // white-space is always considered a literal in user-provided formats
1913
+ // the " " token has a special meaning (see unitForToken)
1914
+
1883
1915
  let current = null,
1884
1916
  currentFull = "",
1885
1917
  bracketed = false;
@@ -1888,7 +1920,7 @@ class Formatter {
1888
1920
  const c = fmt.charAt(i);
1889
1921
  if (c === "'") {
1890
1922
  if (currentFull.length > 0) {
1891
- splits.push({ literal: bracketed, val: currentFull });
1923
+ splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull });
1892
1924
  }
1893
1925
  current = null;
1894
1926
  currentFull = "";
@@ -1899,7 +1931,7 @@ class Formatter {
1899
1931
  currentFull += c;
1900
1932
  } else {
1901
1933
  if (currentFull.length > 0) {
1902
- splits.push({ literal: false, val: currentFull });
1934
+ splits.push({ literal: /^\s+$/.test(currentFull), val: currentFull });
1903
1935
  }
1904
1936
  currentFull = c;
1905
1937
  current = c;
@@ -1907,7 +1939,7 @@ class Formatter {
1907
1939
  }
1908
1940
 
1909
1941
  if (currentFull.length > 0) {
1910
- splits.push({ literal: bracketed, val: currentFull });
1942
+ splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull });
1911
1943
  }
1912
1944
 
1913
1945
  return splits;
@@ -3736,7 +3768,7 @@ class Interval {
3736
3768
  if (!this.isValid) return NaN;
3737
3769
  const start = this.start.startOf(unit),
3738
3770
  end = this.end.startOf(unit);
3739
- return Math.floor(end.diff(start, unit).get(unit)) + 1;
3771
+ return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
3740
3772
  }
3741
3773
 
3742
3774
  /**
@@ -4618,6 +4650,10 @@ function unitForToken(token, loc) {
4618
4650
  // because we don't have any way to figure out what they are
4619
4651
  case "z":
4620
4652
  return simple(/[a-z_+-/]{1,256}?/i);
4653
+ // this special-case "token" represents a place where a macro-token expanded into a white-space literal
4654
+ // in this case we accept any non-newline white-space
4655
+ case " ":
4656
+ return simple(/[^\S\n\r]/);
4621
4657
  default:
4622
4658
  return literal(t);
4623
4659
  }
@@ -4675,9 +4711,10 @@ function tokenForPart(part, formatOpts) {
4675
4711
  const { type, value } = part;
4676
4712
 
4677
4713
  if (type === "literal") {
4714
+ const isSpace = /^\s+$/.test(value);
4678
4715
  return {
4679
- literal: true,
4680
- val: value,
4716
+ literal: !isSpace,
4717
+ val: isSpace ? " " : value,
4681
4718
  };
4682
4719
  }
4683
4720
 
@@ -5147,7 +5184,7 @@ function adjustTime(inst, dur) {
5147
5184
  // by handling the zone options
5148
5185
  function parseDataToDateTime(parsed, parsedZone, opts, format, text, specificOffset) {
5149
5186
  const { setZone, zone } = opts;
5150
- if (parsed && Object.keys(parsed).length !== 0) {
5187
+ if ((parsed && Object.keys(parsed).length !== 0) || parsedZone) {
5151
5188
  const interpretationZone = parsedZone || zone,
5152
5189
  inst = DateTime.fromObject(parsed, {
5153
5190
  ...opts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nymphjs/guid",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "NymphJS - GUID and Unique Code Generators",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -41,14 +41,14 @@
41
41
  "@types/nanoid-dictionary": "^4.2.0",
42
42
  "@types/sha1": "^1.1.3",
43
43
  "jest": "^29.4.3",
44
- "luxon": "^3.2.1",
44
+ "luxon": "^3.3.0",
45
45
  "nanoid": "^4.0.1",
46
46
  "nanoid-dictionary": "^4.3.0",
47
- "rollup": "^3.17.3",
47
+ "rollup": "^3.18.0",
48
48
  "sha1": "^1.1.1",
49
49
  "ts-jest": "^29.0.5",
50
50
  "tslib": "^2.5.0",
51
51
  "typescript": "^4.9.5"
52
52
  },
53
- "gitHead": "812eeec8e5b100c6f82abbae1722cfc64a167046"
53
+ "gitHead": "976040d986831ee0b9a15990adb7e8a48a5379e8"
54
54
  }