inferred-types 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -234,7 +234,8 @@ const COMPARISON_OPERATIONS = [
234
234
  "false",
235
235
  "returnEquals",
236
236
  "returnExtends",
237
- "isTemplateLiteral"
237
+ "isTemplateLiteral",
238
+ "hasLength"
238
239
  ];
239
240
 
240
241
  //#endregion
@@ -7170,7 +7171,7 @@ function isDateLike(val) {
7170
7171
  * type guard which validates that `val` is the type `DateMeta`.
7171
7172
  */
7172
7173
  function isDateMeta(val) {
7173
- return isDictionary(val) && "dateType" in val && DATE_TYPE.includes(val);
7174
+ return isDictionary(val) && "dateType" in val && DATE_TYPE.includes(val.dateType);
7174
7175
  }
7175
7176
 
7176
7177
  //#endregion
@@ -8273,28 +8274,6 @@ function createCssSelector(_opt) {
8273
8274
  };
8274
8275
  }
8275
8276
 
8276
- //#endregion
8277
- //#region src/functions/fnMeta.ts
8278
- /**
8279
- * **fnMeta**(func)
8280
- *
8281
- * Runtime utility which provides a `fn` and `props` property which are
8282
- * decomposed from the input function.
8283
- *
8284
- * - the `fn` is a clone of the underlying function
8285
- */
8286
- function fnMeta(func) {
8287
- const fn$1 = (...args) => func(...args);
8288
- const props = Object.keys(fn$1).reduce((acc, key) => ({
8289
- ...acc,
8290
- [key]: fn$1[key]
8291
- }), {});
8292
- return {
8293
- fn: fn$1,
8294
- props
8295
- };
8296
- }
8297
-
8298
8277
  //#endregion
8299
8278
  //#region src/functions/fnProps.ts
8300
8279
  /**
@@ -8716,6 +8695,10 @@ function handle_other(val, op, params) {
8716
8695
  if (!(val instanceof Error)) return false;
8717
8696
  if (!params[0]) return err(`invalid-params/errorsOfType`, `The 'errorsOfType' operation requires a type parameter`, { params });
8718
8697
  return "type" in val && val.type === params[0];
8698
+ case "hasLength": if (isString(val)) return isNarrowableArray(params) && contains(params, val.length);
8699
+ else if (isNumber(val)) return isNarrowableArray(params) && contains(params, `${val}`.length);
8700
+ else if (isArray(val)) return isNarrowableArray(params) && contains(params, val.length);
8701
+ else return false;
8719
8702
  case "returnEquals":
8720
8703
  if (!isFunction(val)) return false;
8721
8704
  return err(`compare/runtime`, `The comparison type "returnEquals" can not be evaluated in the runtime system!`);
@@ -13001,30 +12984,47 @@ function offsetMinutesToString(mins) {
13001
12984
  */
13002
12985
  function asDateTime(input) {
13003
12986
  if (isMoment(input)) {
13004
- const d = new Date(input.toISOString());
13005
- const tz = isTimezoneOffset(offsetMinutesToString(input.parseZone().utcOffset())) ? offsetMinutesToString(input.parseZone().utcOffset()) : null;
12987
+ const parsed = input.parseZone();
12988
+ const d = new Date(parsed.toISOString());
12989
+ const offsetMins = parsed.utcOffset();
12990
+ const tz = isTimezoneOffset(offsetMinutesToString(offsetMins)) ? offsetMinutesToString(offsetMins) : null;
13006
12991
  d.offset = tz;
13007
12992
  d.tz = isIanaTimezone(input._z?.name) ? input._z.name : null;
13008
12993
  d.source = "moment";
13009
- const sourceIso = input.parseZone().toISOString(true);
12994
+ const sourceIso = parsed.toISOString(true);
13010
12995
  d.sourceIso = sourceIso.endsWith("+00:00") ? sourceIso.replace("+00:00", "Z") : sourceIso;
13011
12996
  return d;
13012
12997
  }
13013
12998
  if (isLuxonDate(input)) {
13014
12999
  const d = input.toJSDate();
13015
- d.offset = input.isOffsetFixed ? offsetMinutesToString(input.offset) : null;
13000
+ d.offset = offsetMinutesToString(input.offset);
13016
13001
  d.tz = isIanaTimezone(input.zoneName) ? input.zoneName : null;
13017
13002
  d.source = "luxon";
13018
- d.sourceIso = input.zoneName === "UTC" ? input.toUTC().toISO() : input.toISO();
13003
+ d.sourceIso = input.toISO();
13019
13004
  return d;
13020
13005
  }
13021
13006
  if (isTemporalDate(input)) {
13022
- const zdt = "epochNanoseconds" in input ? input.toZonedDateTimeISO(getLocalIanaZone()) : input;
13023
- const d = new Date(zdt.epochMilliseconds);
13024
- d.offset = isTimezoneOffset(zdt.offset) ? zdt.offset : null;
13025
- d.tz = isIanaTimezone(zdt.timeZone.id) ? zdt.timeZone.id : null;
13007
+ let d;
13008
+ if ("epochNanoseconds" in input) {
13009
+ const zdt = input.toZonedDateTimeISO(getLocalIanaZone());
13010
+ d = new Date(zdt.epochMilliseconds);
13011
+ d.offset = isTimezoneOffset(zdt.offset) ? zdt.offset : null;
13012
+ d.tz = zdt.timeZone && isIanaTimezone(zdt.timeZone.id) ? zdt.timeZone.id : null;
13013
+ d.sourceIso = zdt.toString();
13014
+ } else if ("timeZone" in input) {
13015
+ const zdt = input;
13016
+ d = new Date(zdt.epochMilliseconds);
13017
+ d.offset = isTimezoneOffset(zdt.offset) ? zdt.offset : null;
13018
+ d.tz = zdt.timeZone && isIanaTimezone(zdt.timeZone.id) ? zdt.timeZone.id : null;
13019
+ d.sourceIso = zdt.toString();
13020
+ } else {
13021
+ const instant = input.toZonedDateTime("UTC").toInstant();
13022
+ d = new Date(instant.epochMilliseconds);
13023
+ d.offset = null;
13024
+ d.tz = null;
13025
+ d.sourceIso = null;
13026
+ }
13026
13027
  d.source = "temporal";
13027
- d.sourceIso = zdt.toString();
13028
13028
  return d;
13029
13029
  }
13030
13030
  if (isDayJs(input)) {
@@ -13674,17 +13674,26 @@ function parseDate(d) {
13674
13674
  */
13675
13675
  function parseDateObject(d) {
13676
13676
  const date = d instanceof Date ? d : asDateTime(d);
13677
+ if (isError(date)) return date;
13677
13678
  const utcIso = date.toISOString();
13678
13679
  const utcParsed = parseIsoDate(utcIso);
13679
- if (isError(utcParsed)) throw utcParsed;
13680
- const sourceIso = date.sourceIso;
13680
+ if (isError(utcParsed)) return utcParsed;
13681
+ const datePlus = date;
13682
+ const sourceIso = datePlus.sourceIso;
13681
13683
  if (sourceIso) {
13682
13684
  const sourceParsed = parseIsoDate(sourceIso);
13683
- if (!isError(sourceParsed) && sourceParsed.timezone) return {
13684
- ...utcParsed,
13685
- timezone: sourceParsed.timezone
13686
- };
13685
+ if (isDateMeta(sourceParsed) && sourceParsed.timezone) {
13686
+ const timezone = sourceParsed.timezone === "+00:00" ? "Z" : sourceParsed.timezone;
13687
+ return {
13688
+ ...utcParsed,
13689
+ timezone
13690
+ };
13691
+ }
13687
13692
  }
13693
+ if (datePlus.offset === null && datePlus.source) return {
13694
+ ...utcParsed,
13695
+ timezone: null
13696
+ };
13688
13697
  return utcParsed;
13689
13698
  }
13690
13699
 
@@ -16287,7 +16296,6 @@ exports.filterUndefined = filterUndefined;
16287
16296
  exports.find = find;
16288
16297
  exports.firstChar = firstChar;
16289
16298
  exports.fn = fn;
16290
- exports.fnMeta = fnMeta;
16291
16299
  exports.fnProps = fnProps;
16292
16300
  exports.fourDigitYear = fourDigitYear;
16293
16301
  exports.freeze = freeze;