@aglyn/shared-util-tools 1.0.0-beta.218 → 1.0.0-beta.220

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/shared-util-tools",
3
- "version": "1.0.0-beta.218",
3
+ "version": "1.0.0-beta.220",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/shared-data-types": "1.0.0-beta.218",
28
+ "@aglyn/shared-data-types": "1.0.0-beta.220",
29
29
  "@swc/helpers": "0.5.23",
30
30
  "lodash-es": "^4.18.1",
31
31
  "php-serialize": "^5.1.3"
@@ -14,8 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- type ToNumType = 'int' | 'float' | 'eval';
18
- type ToNumResult<T extends ToNumType = never> = ConditionalNonDist<T, 'eval', any, number>;
17
+ type ToNumType = 'int' | 'float';
19
18
  export type ToNumOptions<T extends ToNumType = never, N = 0> = {
20
19
  onNaN?: N;
21
20
  type?: 'int';
@@ -29,13 +28,12 @@ export type ToNumOptions<T extends ToNumType = never, N = 0> = {
29
28
  * Ensure and parse any value to a number.
30
29
  *
31
30
  * - If radix, `{type: 'int'}` is provided will use {@link parseInt}
32
- * - If `{type: 'parse'}` is provided will use {@link parseFloat}
33
- * - If `{type: 'eval'}` is provided will use {@link eval} and {@link Number}
31
+ * - If `{type: 'float'}` is provided will use {@link parseFloat}
34
32
  * - Otherwise uses {@link Number|Number(val)}
35
33
  * - If parsing results in NaN will return {@link onNaN}.
36
34
  *
37
35
  * @param val - the value to parse into a number
38
36
  * @param options - override default parsing behavior
39
37
  */
40
- export declare function toNum<T extends ToNumType, N = 0>(val: string | any, options?: ToNumOptions<T, N>): ToNumResult<T> | N;
38
+ export declare function toNum<T extends ToNumType, N = 0>(val: string | any, options?: ToNumOptions<T, N>): number | N;
41
39
  export {};
@@ -19,8 +19,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
19
19
  * Ensure and parse any value to a number.
20
20
  *
21
21
  * - If radix, `{type: 'int'}` is provided will use {@link parseInt}
22
- * - If `{type: 'parse'}` is provided will use {@link parseFloat}
23
- * - If `{type: 'eval'}` is provided will use {@link eval} and {@link Number}
22
+ * - If `{type: 'float'}` is provided will use {@link parseFloat}
24
23
  * - Otherwise uses {@link Number|Number(val)}
25
24
  * - If parsing results in NaN will return {@link onNaN}.
26
25
  *
@@ -32,7 +31,6 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
32
31
  if (_isNumT(radix)) parsed = parseInt(val, radix);
33
32
  else if (type === 'int') parsed = parseInt(val);
34
33
  else if (type === 'float') parsed = parseFloat(val);
35
- else if (type === 'eval') parsed = Number(eval(val));
36
34
  else if (!type) parsed = Number(val);
37
35
  if (isNaN(parsed)) parsed = onNaN != null ? onNaN : 0;
38
36
  return parsed;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/number/to-num.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2023 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { _isNumT } from '../guards/lib/_is-num-t'\n\ntype ToNumType = 'int' | 'float' | 'eval'\ntype ToNumResult<T extends ToNumType = never> = ConditionalNonDist<\n T,\n 'eval',\n any,\n number\n>\n\nexport type ToNumOptions<T extends ToNumType = never, N = 0> =\n | { onNaN?: N; type?: 'int'; radix?: number }\n | { onNaN?: N; type?: T; radix?: never }\n\n/**\n * Ensure and parse any value to a number.\n *\n * - If radix, `{type: 'int'}` is provided will use {@link parseInt}\n * - If `{type: 'parse'}` is provided will use {@link parseFloat}\n * - If `{type: 'eval'}` is provided will use {@link eval} and {@link Number}\n * - Otherwise uses {@link Number|Number(val)}\n * - If parsing results in NaN will return {@link onNaN}.\n *\n * @param val - the value to parse into a number\n * @param options - override default parsing behavior\n */\nexport function toNum<T extends ToNumType, N = 0>(\n val: string | any,\n options?: ToNumOptions<T, N>,\n): ToNumResult<T> | N {\n const { type, onNaN, radix } = { ...options }\n let parsed: ToNumResult<T> | N = NaN\n\n if (_isNumT(radix)) parsed = parseInt(val, radix)\n else if (type === 'int') parsed = parseInt(val)\n else if (type === 'float') parsed = parseFloat(val)\n else if (type === 'eval') parsed = Number(eval(val))\n else if (!type) parsed = Number(val)\n if (isNaN(parsed)) parsed = onNaN ?? 0\n\n return parsed\n}\n"],"names":["_isNumT","toNum","val","options","type","onNaN","radix","parsed","NaN","parseInt","parseFloat","Number","eval","isNaN"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,OAAO,QAAQ,6BAAyB;AAcjD;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,MACdC,GAAiB,EACjBC,OAA4B;IAE5B,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAG,aAAKH;IACpC,IAAII,SAA6BC;IAEjC,IAAIR,QAAQM,QAAQC,SAASE,SAASP,KAAKI;SACtC,IAAIF,SAAS,OAAOG,SAASE,SAASP;SACtC,IAAIE,SAAS,SAASG,SAASG,WAAWR;SAC1C,IAAIE,SAAS,QAAQG,SAASI,OAAOC,KAAKV;SAC1C,IAAI,CAACE,MAAMG,SAASI,OAAOT;IAChC,IAAIW,MAAMN,SAASA,SAASF,gBAAAA,QAAS;IAErC,OAAOE;AACT"}
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/number/to-num.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2023 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { _isNumT } from '../guards/lib/_is-num-t'\n\ntype ToNumType = 'int' | 'float'\n\nexport type ToNumOptions<T extends ToNumType = never, N = 0> =\n | { onNaN?: N; type?: 'int'; radix?: number }\n | { onNaN?: N; type?: T; radix?: never }\n\n/**\n * Ensure and parse any value to a number.\n *\n * - If radix, `{type: 'int'}` is provided will use {@link parseInt}\n * - If `{type: 'float'}` is provided will use {@link parseFloat}\n * - Otherwise uses {@link Number|Number(val)}\n * - If parsing results in NaN will return {@link onNaN}.\n *\n * @param val - the value to parse into a number\n * @param options - override default parsing behavior\n */\nexport function toNum<T extends ToNumType, N = 0>(\n val: string | any,\n options?: ToNumOptions<T, N>,\n): number | N {\n const { type, onNaN, radix } = { ...options }\n let parsed: number | N = NaN\n\n if (_isNumT(radix)) parsed = parseInt(val, radix)\n else if (type === 'int') parsed = parseInt(val)\n else if (type === 'float') parsed = parseFloat(val)\n else if (!type) parsed = Number(val)\n if (isNaN(parsed)) parsed = onNaN ?? 0\n\n return parsed\n}\n"],"names":["_isNumT","toNum","val","options","type","onNaN","radix","parsed","NaN","parseInt","parseFloat","Number","isNaN"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,OAAO,QAAQ,6BAAyB;AAQjD;;;;;;;;;;CAUC,GACD,OAAO,SAASC,MACdC,GAAiB,EACjBC,OAA4B;IAE5B,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAG,aAAKH;IACpC,IAAII,SAAqBC;IAEzB,IAAIR,QAAQM,QAAQC,SAASE,SAASP,KAAKI;SACtC,IAAIF,SAAS,OAAOG,SAASE,SAASP;SACtC,IAAIE,SAAS,SAASG,SAASG,WAAWR;SAC1C,IAAI,CAACE,MAAMG,SAASI,OAAOT;IAChC,IAAIU,MAAML,SAASA,SAASF,gBAAAA,QAAS;IAErC,OAAOE;AACT"}