@awsless/validate 0.0.2 → 0.0.4

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/dist/index.cjs CHANGED
@@ -88,7 +88,13 @@ var bigfloat = () => {
88
88
  const base = (0, import_superstruct.define)("bigfloat", (value) => {
89
89
  return value instanceof import_big_float.BigFloat || "Invalid number";
90
90
  });
91
- return (0, import_superstruct.coerce)(base, (0, import_superstruct.union)([(0, import_superstruct.string)(), (0, import_superstruct.number)()]), (value) => {
91
+ const bigFloatLike = (0, import_superstruct.coerce)(base, (0, import_superstruct.object)({
92
+ exponent: (0, import_superstruct.number)(),
93
+ coefficient: (0, import_superstruct.bigint)()
94
+ }), (value) => {
95
+ return new import_big_float.BigFloat(value);
96
+ });
97
+ return (0, import_superstruct.coerce)(bigFloatLike, (0, import_superstruct.union)([(0, import_superstruct.string)(), (0, import_superstruct.number)()]), (value) => {
92
98
  if (typeof value === "string" && value !== "" || typeof value === "number") {
93
99
  if (!isNaN(Number(value))) {
94
100
  return new import_big_float.BigFloat(value);
@@ -99,15 +105,16 @@ var bigfloat = () => {
99
105
  };
100
106
  var positive = (struct2) => {
101
107
  const expected = `Expected a positive ${struct2.type}`;
102
- const zero = new import_big_float.BigFloat(0);
108
+ const ZERO = new import_big_float.BigFloat(0);
103
109
  return (0, import_superstruct.refine)(struct2, "positive", (value) => {
104
- return (0, import_big_float.gt)(value, zero) || `${expected} but received '${value}'`;
110
+ return (0, import_big_float.gt)(value, ZERO) || `${expected} but received '${value}'`;
105
111
  });
106
112
  };
107
113
  var precision = (struct2, decimals) => {
108
114
  const expected = `Expected a ${struct2.type}`;
109
115
  return (0, import_superstruct.refine)(struct2, "precision", (value) => {
110
- return -value.exponent <= decimals || `${expected} with ${decimals} decimals`;
116
+ const big = new import_big_float.BigFloat(value);
117
+ return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
111
118
  });
112
119
  };
113
120
 
package/dist/index.d.ts CHANGED
@@ -4,8 +4,8 @@ import { BigFloat } from '@awsless/big-float';
4
4
  import { UUID } from 'crypto';
5
5
 
6
6
  declare const bigfloat: () => Struct<BigFloat, null>;
7
- declare const positive: <T extends BigFloat, S extends unknown>(struct: Struct<T, S>) => Struct<T, S>;
8
- declare const precision: <T extends BigFloat, S extends unknown>(struct: Struct<T, S>, decimals: number) => Struct<T, S>;
7
+ declare const positive: <T extends number | BigFloat, S extends unknown>(struct: Struct<T, S>) => Struct<T, S>;
8
+ declare const precision: <T extends number | BigFloat, S extends unknown>(struct: Struct<T, S>, decimals: number) => Struct<T, S>;
9
9
 
10
10
  declare const date: () => Struct<Date, null>;
11
11
 
package/dist/index.js CHANGED
@@ -1,11 +1,17 @@
1
1
  // src/types/bigfloat.ts
2
- import { coerce, define, number, string, union, refine } from "superstruct";
2
+ import { coerce, define, number, string, union, refine, object, bigint } from "superstruct";
3
3
  import { BigFloat, gt } from "@awsless/big-float";
4
4
  var bigfloat = () => {
5
5
  const base = define("bigfloat", (value) => {
6
6
  return value instanceof BigFloat || "Invalid number";
7
7
  });
8
- return coerce(base, union([string(), number()]), (value) => {
8
+ const bigFloatLike = coerce(base, object({
9
+ exponent: number(),
10
+ coefficient: bigint()
11
+ }), (value) => {
12
+ return new BigFloat(value);
13
+ });
14
+ return coerce(bigFloatLike, union([string(), number()]), (value) => {
9
15
  if (typeof value === "string" && value !== "" || typeof value === "number") {
10
16
  if (!isNaN(Number(value))) {
11
17
  return new BigFloat(value);
@@ -16,15 +22,16 @@ var bigfloat = () => {
16
22
  };
17
23
  var positive = (struct2) => {
18
24
  const expected = `Expected a positive ${struct2.type}`;
19
- const zero = new BigFloat(0);
25
+ const ZERO = new BigFloat(0);
20
26
  return refine(struct2, "positive", (value) => {
21
- return gt(value, zero) || `${expected} but received '${value}'`;
27
+ return gt(value, ZERO) || `${expected} but received '${value}'`;
22
28
  });
23
29
  };
24
30
  var precision = (struct2, decimals) => {
25
31
  const expected = `Expected a ${struct2.type}`;
26
32
  return refine(struct2, "precision", (value) => {
27
- return -value.exponent <= decimals || `${expected} with ${decimals} decimals`;
33
+ const big = new BigFloat(value);
34
+ return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
28
35
  });
29
36
  };
30
37
 
@@ -94,7 +101,7 @@ import {
94
101
  refine as refine3,
95
102
  any,
96
103
  array,
97
- bigint,
104
+ bigint as bigint2,
98
105
  boolean,
99
106
  enums,
100
107
  func,
@@ -106,7 +113,7 @@ import {
106
113
  never,
107
114
  nullable,
108
115
  number as number2,
109
- object,
116
+ object as object2,
110
117
  optional,
111
118
  record,
112
119
  regexp,
@@ -140,7 +147,7 @@ export {
140
147
  assert,
141
148
  assign,
142
149
  bigfloat,
143
- bigint,
150
+ bigint2 as bigint,
144
151
  boolean,
145
152
  coerce5 as coerce,
146
153
  create,
@@ -168,7 +175,7 @@ export {
168
175
  nonempty,
169
176
  nullable,
170
177
  number2 as number,
171
- object,
178
+ object2 as object,
172
179
  omit,
173
180
  optional,
174
181
  partial,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/validate",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,10 +24,10 @@
24
24
  }
25
25
  },
26
26
  "peerDependencies": {
27
- "@awsless/big-float": "^0.0.1"
27
+ "@awsless/big-float": "^0.0.3"
28
28
  },
29
29
  "devDependencies": {
30
- "@awsless/big-float": "^0.0.1"
30
+ "@awsless/big-float": "^0.0.3"
31
31
  },
32
32
  "dependencies": {
33
33
  "superstruct": "^1.0.3"