inferred-types 1.1.3 → 1.2.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.
@@ -14915,44 +14915,6 @@ function doesExtend(type) {
14915
14915
  };
14916
14916
  }
14917
14917
 
14918
- //#endregion
14919
- //#region src/runtime-types/shape.ts
14920
- function isAddOrDone(val) {
14921
- return isDictionary(val) && hasKeys("add", "done") && typeof val.done === "function" && typeof val.add === "function";
14922
- }
14923
- const ShapeApiImplementation = {
14924
- boolean,
14925
- unknown,
14926
- undefined: undefinedType,
14927
- null: nullType,
14928
- fn,
14929
- record,
14930
- array,
14931
- set,
14932
- map,
14933
- weakMap
14934
- };
14935
- /**
14936
- * **shape**(s => s.[API])
14937
- *
14938
- * Provides a callback API to allow for defining a type (_which
14939
- * retains a runtime value which will map back to the type_)
14940
- *
14941
- * **Related:** `isShape(val)`
14942
- */
14943
- function shape(cb) {
14944
- const rtn = cb(ShapeApiImplementation);
14945
- return handleDoneFn(isAddOrDone(rtn) ? rtn.done() : rtn);
14946
- }
14947
- /**
14948
- * **isShape**(val)
14949
- *
14950
- * Type guard which tests whether a value is a _type_ defined by a `Shape`.
14951
- */
14952
- function isShape(v) {
14953
- return !!(isString(v) && v.startsWith("<<") && v.endsWith(">>") && SHAPE_PREFIXES.some((i) => v.startsWith(`<<${i}`)));
14954
- }
14955
-
14956
14918
  //#endregion
14957
14919
  //#region src/runtime-types/shape-helpers/addToken.ts
14958
14920
  /**
@@ -14996,6 +14958,62 @@ function fn(..._args) {
14996
14958
  };
14997
14959
  }
14998
14960
 
14961
+ //#endregion
14962
+ //#region src/runtime-types/shape-helpers/wide-containers.ts
14963
+ function record(_key, _value) {
14964
+ return null;
14965
+ }
14966
+ function array(_type) {
14967
+ return null;
14968
+ }
14969
+ function set(_type) {
14970
+ return null;
14971
+ }
14972
+ function map(_key, _value) {
14973
+ return null;
14974
+ }
14975
+ function weakMap(_key, _value) {
14976
+ return null;
14977
+ }
14978
+
14979
+ //#endregion
14980
+ //#region src/runtime-types/shape.ts
14981
+ function isAddOrDone(val) {
14982
+ return isDictionary(val) && hasKeys("add", "done") && typeof val.done === "function" && typeof val.add === "function";
14983
+ }
14984
+ const ShapeApiImplementation = {
14985
+ boolean,
14986
+ unknown,
14987
+ undefined: undefinedType,
14988
+ null: nullType,
14989
+ fn,
14990
+ record,
14991
+ array,
14992
+ set,
14993
+ map,
14994
+ weakMap
14995
+ };
14996
+ /**
14997
+ * **shape**(s => s.[API])
14998
+ *
14999
+ * Provides a callback API to allow for defining a type (_which
15000
+ * retains a runtime value which will map back to the type_)
15001
+ *
15002
+ * **Related:** `isShape(val)`
15003
+ */
15004
+ function shape(cb) {
15005
+ const rtn = cb(ShapeApiImplementation);
15006
+ return handleDoneFn(isAddOrDone(rtn) ? rtn.done() : rtn);
15007
+ }
15008
+ /**
15009
+ * **isShape**(val)
15010
+ *
15011
+ * Type guard which tests whether a value is a _type_ defined by a `Shape`.
15012
+ */
15013
+ function isShape(v) {
15014
+ return !!(isString(v) && v.startsWith("<<") && v.endsWith(">>") && SHAPE_PREFIXES.some((i) => v.startsWith(`<<${i}`)));
15015
+ }
15016
+
14999
15017
  //#endregion
15000
15018
  //#region src/runtime-types/shape-helpers/getTokenData.ts
15001
15019
  /**
@@ -15039,24 +15057,6 @@ function regexToken(re, ...rep) {
15039
15057
  return token;
15040
15058
  }
15041
15059
 
15042
- //#endregion
15043
- //#region src/runtime-types/shape-helpers/wide-containers.ts
15044
- function record(_key, _value) {
15045
- return null;
15046
- }
15047
- function array(_type) {
15048
- return null;
15049
- }
15050
- function set(_type) {
15051
- return null;
15052
- }
15053
- function map(_key, _value) {
15054
- return null;
15055
- }
15056
- function weakMap(_key, _value) {
15057
- return null;
15058
- }
15059
-
15060
15060
  //#endregion
15061
15061
  //#region src/runtime-types/tokens/asOutputToken.ts
15062
15062
  function asOutputFunction(_val) {}
@@ -15164,7 +15164,18 @@ function getTokenKind(token) {
15164
15164
 
15165
15165
  //#endregion
15166
15166
  //#region src/runtime-types/tokens/input-tokens/asInputToken.ts
15167
- function asInputToken(_defn) {}
15167
+ /**
15168
+ * **asInputToken**`(token) -> string`
15169
+ *
15170
+ * Takes an input token(string or otherwise) and returns it as a string token.
15171
+ *
15172
+ * **Note:** until the runtime type parser is finished this will not produce
15173
+ * a runtime errors when an invalid token is passed in but the _type_ will
15174
+ * be set because it benefits from type utilities which are already in place.
15175
+ */
15176
+ function asInputToken(token) {
15177
+ return isString(token) ? token : isDictionary(token) ? toStringLiteral__Object(token) : isArray(token) ? fromInputToken(token) : Never;
15178
+ }
15168
15179
 
15169
15180
  //#endregion
15170
15181
  //#region src/runtime-types/tokens/input-tokens/asStringInputToken.ts
@@ -16026,7 +16037,9 @@ function stripParenthesis(val) {
16026
16037
  * Converts the passed in value to a strongly typed string
16027
16038
  * literal representation of the JSON type for `val`.
16028
16039
  *
16029
- * **Related:** `toStringLiteral()`
16040
+ * **Related:** `toStringLiteral()`, `toJson()`
16041
+ *
16042
+ * @deprecated use `toJson()` instead
16030
16043
  */
16031
16044
  function toJSON(val, _options = {
16032
16045
  quote: "\"",
@@ -16034,6 +16047,20 @@ function toJSON(val, _options = {
16034
16047
  }) {
16035
16048
  return JSON.stringify(val);
16036
16049
  }
16050
+ /**
16051
+ * **toJson**`(val)`
16052
+ *
16053
+ * Converts the passed in value to a strongly typed string
16054
+ * literal representation of the JSON type for `val`.
16055
+ *
16056
+ * **Related:** `toStringLiteral()`
16057
+ */
16058
+ function toJson(val, _options = {
16059
+ quote: "\"",
16060
+ encode: false
16061
+ }) {
16062
+ return JSON.stringify(val);
16063
+ }
16037
16064
 
16038
16065
  //#endregion
16039
16066
  //#region src/type-conversion/toKeyValue.ts
@@ -16111,6 +16138,13 @@ function property(prop) {
16111
16138
  }
16112
16139
  return String(prop);
16113
16140
  }
16141
+ /**
16142
+ * **toStringLiteral__Object**`(obj) -> token`
16143
+ *
16144
+ * Converts a `DefineObject` shaped type definition into a string based
16145
+ * `InputToken` while converting the _type_ to the type which the token
16146
+ * represents.
16147
+ */
16114
16148
  function toStringLiteral__Object(obj) {
16115
16149
  const inner = [];
16116
16150
  for (const k of keysOf(obj)) inner.push(`${property(k)}: ${obj[k]}`);
@@ -16780,6 +16814,7 @@ exports.toCamelCase = toCamelCase;
16780
16814
  exports.toInteger = toInteger;
16781
16815
  exports.toIsoDateString = toIsoDateString;
16782
16816
  exports.toJSON = toJSON;
16817
+ exports.toJson = toJson;
16783
16818
  exports.toKebabCase = toKebabCase;
16784
16819
  exports.toKeyValue = toKeyValue;
16785
16820
  exports.toLowercase = toLowercase;
@@ -16789,6 +16824,7 @@ exports.toPascalCase = toPascalCase;
16789
16824
  exports.toSnakeCase = toSnakeCase;
16790
16825
  exports.toString = toString;
16791
16826
  exports.toStringLiteral = toStringLiteral;
16827
+ exports.toStringLiteral__Object = toStringLiteral__Object;
16792
16828
  exports.toStringLiteral__Tuple = toStringLiteral__Tuple;
16793
16829
  exports.toStringToken = toStringToken;
16794
16830
  exports.trim = trim;