@awsless/validate 0.0.1 → 0.0.3

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
@@ -99,15 +99,16 @@ var bigfloat = () => {
99
99
  };
100
100
  var positive = (struct2) => {
101
101
  const expected = `Expected a positive ${struct2.type}`;
102
- const zero = new import_big_float.BigFloat(0);
102
+ const ZERO = new import_big_float.BigFloat(0);
103
103
  return (0, import_superstruct.refine)(struct2, "positive", (value) => {
104
- return (0, import_big_float.gt)(value, zero) || `${expected} but received '${value}'`;
104
+ return (0, import_big_float.gt)(value, ZERO) || `${expected} but received '${value}'`;
105
105
  });
106
106
  };
107
107
  var precision = (struct2, decimals) => {
108
108
  const expected = `Expected a ${struct2.type}`;
109
109
  return (0, import_superstruct.refine)(struct2, "precision", (value) => {
110
- return -value.exponent <= decimals || `${expected} with ${decimals} decimals`;
110
+ const big = new import_big_float.BigFloat(value);
111
+ return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
111
112
  });
112
113
  };
113
114
 
package/dist/index.d.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { Struct } from 'superstruct';
2
2
  export { Coercer, Context, Describe, Failure, Infer, Refiner, Result, Struct, StructError, Validator, any, array, assert, assign, bigint, boolean, coerce, create, defaulted, define, deprecated, dynamic, empty, enums, func, instance, integer, intersection, is, lazy, literal, map, mask, max, min, never, nonempty, nullable, number, object, omit, optional, partial, pattern, pick, record, refine, regexp, set, size, string, struct, trimmed, tuple, type, union, unknown } from 'superstruct';
3
3
  import { BigFloat } from '@awsless/big-float';
4
+ import { UUID } from 'crypto';
4
5
 
5
6
  declare const bigfloat: () => Struct<BigFloat, null>;
6
- declare const positive: <T extends BigFloat, S extends unknown>(struct: Struct<T, S>) => Struct<T, S>;
7
- 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>;
8
9
 
9
10
  declare const date: () => Struct<Date, null>;
10
11
 
11
- declare const uuid: () => Struct<string, null>;
12
+ declare const uuid: () => Struct<UUID, null>;
12
13
 
13
14
  declare const json: <T, S>(struct: Struct<T, S>) => Struct<T, S>;
14
15
 
package/dist/index.js CHANGED
@@ -16,15 +16,16 @@ var bigfloat = () => {
16
16
  };
17
17
  var positive = (struct2) => {
18
18
  const expected = `Expected a positive ${struct2.type}`;
19
- const zero = new BigFloat(0);
19
+ const ZERO = new BigFloat(0);
20
20
  return refine(struct2, "positive", (value) => {
21
- return gt(value, zero) || `${expected} but received '${value}'`;
21
+ return gt(value, ZERO) || `${expected} but received '${value}'`;
22
22
  });
23
23
  };
24
24
  var precision = (struct2, decimals) => {
25
25
  const expected = `Expected a ${struct2.type}`;
26
26
  return refine(struct2, "precision", (value) => {
27
- return -value.exponent <= decimals || `${expected} with ${decimals} decimals`;
27
+ const big = new BigFloat(value);
28
+ return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
28
29
  });
29
30
  };
30
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/validate",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
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.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@awsless/big-float": "^0.0.1"
30
+ "@awsless/big-float": "^0.0.2"
31
31
  },
32
32
  "dependencies": {
33
33
  "superstruct": "^1.0.3"
@@ -35,6 +35,6 @@
35
35
  "scripts": {
36
36
  "test": "pnpm code test",
37
37
  "build": "pnpm tsup src/index.ts --format cjs,esm --dts --clean",
38
- "prepublish": "pnpm build"
38
+ "prepublish": "if pnpm test; then pnpm build; else exit; fi"
39
39
  }
40
40
  }