Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

Commit 7f1ce8c

Browse files
authored
fix(parser): infer array & object (#18)
1 parent 00197c1 commit 7f1ce8c

File tree

4 files changed

+55
-51
lines changed

4 files changed

+55
-51
lines changed

CHANGELOG.md

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,85 @@
1+
## 4.0.1 (24 Oct 2022)
2+
3+
- (Fix) Infer array and object chain functions parser
4+
15
## 4.0.0 (23 Oct 2022)
26

3-
- (Feat) Provided chaining method, which is more readable but slower according
4-
to benchmarking
5-
- (Feat) Provided named parameters alternative to chaining method, which is less
6-
readable but faster according to benchmarking
7+
- (Feat) Provided chaining method, which is more readable but slower according
8+
to benchmarking
9+
- (Feat) Provided named parameters alternative to chaining method, which is less
10+
readable but faster according to benchmarking
711

812
## 3.0.1 (23 Oct 2022)
913

10-
- (Fix) Infer `elseLazyGet`
14+
- (Fix) Infer `elseLazyGet`
1115

1216
## 3.0.0 (9 Oct 2022)
1317

14-
- (Feat) Each validation method will only return `elseGet(t: T)` and
15-
`elseThrow(message: string)` for simplicity and improvement of overall
16-
execution speed
17-
- (Feat) Number parser will also return an additional object, `inRangeOf`, which
18-
in turn return validation method specified above
18+
- (Feat) Each validation method will only return `elseGet(t: T)` and
19+
`elseThrow(message: string)` for simplicity and improvement of overall
20+
execution speed
21+
- (Feat) Number parser will also return an additional object, `inRangeOf`, which
22+
in turn return validation method specified above
1923

2024
## 2.0.4 (31 July 2022)
2125

22-
- (Fix) Automate addtion of `.js` extension for mjs export
26+
- (Fix) Automate addtion of `.js` extension for mjs export
2327

2428
## 2.0.3 (19 July 2022)
2529

26-
- (Fix) Improved CommonJs & remove duplicated type definition
30+
- (Fix) Improved CommonJs & remove duplicated type definition
2731

2832
## 2.0.2 (19 July 2022)
2933

30-
- (Feat) Added support for CommonJs
34+
- (Feat) Added support for CommonJs
3135

3236
## 2.0.1 (18 Jun 2022)
3337

34-
- (Fix) Removed parser for `map` and `set` as it cannot be stringified by JSON
35-
(really forgot about it)
38+
- (Fix) Removed parser for `map` and `set` as it cannot be stringified by JSON
39+
(really forgot about it)
3640

3741
## 2.0.0 (1 June 2022)
3842

39-
- (Feat!) Removed parser for `bigint`, `Symbol`, `undefined` and `function` as
40-
it cannot be stringified by JSON
41-
- (Chore) Removed unused dependencies
43+
- (Feat!) Removed parser for `bigint`, `Symbol`, `undefined` and `function` as
44+
it cannot be stringified by JSON
45+
- (Chore) Removed unused dependencies
4246

4347
## 1.0.3 (12 Feb 2022)
4448

45-
- (Fix) Added parseAsCustomType in export statement
49+
- (Fix) Added parseAsCustomType in export statement
4650

4751
## 1.0.2 (12 Feb 2022)
4852

49-
- (Feat) Added parseAsCustomType for parsing as a specific type of non-object
50-
type
51-
- (Fix) Changed spelling typo of `parsedAs` to `parseAs`
53+
- (Feat) Added parseAsCustomType for parsing as a specific type of non-object
54+
type
55+
- (Fix) Changed spelling typo of `parsedAs` to `parseAs`
5256

5357
## 1.0.1 (7 Jan 2022)
5458

55-
- (Fix) Changed types in package.json to direct to proper definition as
56-
previously I did not point it to index.d.ts
57-
- (Feat) Added `orElseLazyGet()` as an alternative lazy loading version of
58-
`orElseGet()`
59-
- (Feat) Freeze readonly object or data structure so that it will throw run time
60-
error when there's an attempt to mutate it in JavaScript
59+
- (Fix) Changed types in package.json to direct to proper definition as
60+
previously I did not point it to index.d.ts
61+
- (Feat) Added `orElseLazyGet()` as an alternative lazy loading version of
62+
`orElseGet()`
63+
- (Feat) Freeze readonly object or data structure so that it will throw run time
64+
error when there's an attempt to mutate it in JavaScript
6165

6266
## 1.0.0 (5 Jan 2022)
6367

64-
- (Feat) Added parsing for array, map, set and object
65-
- (Feat!) Changed parsing for boolean, string, numbers and bigint
68+
- (Feat) Added parsing for array, map, set and object
69+
- (Feat!) Changed parsing for boolean, string, numbers and bigint
6670

6771
## 0.0.3 (4 Dec 2021)
6872

69-
- (Fix) Added types in package.json
73+
- (Fix) Added types in package.json
7074

7175
## 0.0.2 (4 Dec 2021)
7276

73-
- (Fix) Added type: module in package.json
77+
- (Fix) Added type: module in package.json
7478

7579
## 0.0.1 (4 Dec 2021)
7680

77-
- (Fix) Changed main entry point in package.json
81+
- (Fix) Changed main entry point in package.json
7882

7983
## 0.0.0 (4 Dec 2021)
8084

81-
- (Feat) Initial public release
85+
- (Feat) Initial public release

dist/parser/class/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ class Parser {
2020
asCustom = <C>(predicate: ConstructorParameters<typeof CustomParser>[1]) =>
2121
new CustomParser<C>(this.value, predicate);
2222

23-
asMutableArray = (
24-
parseElement: ConstructorParameters<typeof MutableArrayParser>[1]
23+
asMutableArray = <E>(
24+
parseElement: ConstructorParameters<typeof MutableArrayParser<E>>[1]
2525
) => new MutableArrayParser(this.value, parseElement);
26-
asReadonlyArray = (
27-
parseElement: ConstructorParameters<typeof ReadonlyArrayParser>[1]
26+
asReadonlyArray = <E>(
27+
parseElement: ConstructorParameters<typeof ReadonlyArrayParser<E>>[1]
2828
) => new ReadonlyArrayParser(this.value, parseElement);
2929

30-
asMutableObject = (
31-
parse: ConstructorParameters<typeof MutableObjectParser>[1]
30+
asMutableObject = <O extends Object>(
31+
parse: ConstructorParameters<typeof MutableObjectParser<O>>[1]
3232
) => new MutableObjectParser(this.value, parse);
33-
asReadonlyObject = (
34-
parse: ConstructorParameters<typeof ReadonlyObjectParser>[1]
33+
asReadonlyObject = <O extends Object>(
34+
parse: ConstructorParameters<typeof ReadonlyObjectParser<O>>[1]
3535
) => new ReadonlyObjectParser(this.value, parse);
3636
}
3737

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "parse-dont-validate",
33
"description": "Verify the integrity of the data and return it in expected shape. Otherwise throw error or return a specified default value",
4-
"version": "4.0.0",
4+
"version": "4.0.1",
55
"license": "MIT",
66
"main": "build/cjs/index.js",
77
"module": "build/mjs/index.js",

src/parser/class/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ class Parser {
2020
asCustom = <C>(predicate: ConstructorParameters<typeof CustomParser>[1]) =>
2121
new CustomParser<C>(this.value, predicate);
2222

23-
asMutableArray = (
24-
parseElement: ConstructorParameters<typeof MutableArrayParser>[1]
23+
asMutableArray = <E>(
24+
parseElement: ConstructorParameters<typeof MutableArrayParser<E>>[1]
2525
) => new MutableArrayParser(this.value, parseElement);
26-
asReadonlyArray = (
27-
parseElement: ConstructorParameters<typeof ReadonlyArrayParser>[1]
26+
asReadonlyArray = <E>(
27+
parseElement: ConstructorParameters<typeof ReadonlyArrayParser<E>>[1]
2828
) => new ReadonlyArrayParser(this.value, parseElement);
2929

30-
asMutableObject = (
31-
parse: ConstructorParameters<typeof MutableObjectParser>[1]
30+
asMutableObject = <O extends Object>(
31+
parse: ConstructorParameters<typeof MutableObjectParser<O>>[1]
3232
) => new MutableObjectParser(this.value, parse);
33-
asReadonlyObject = (
34-
parse: ConstructorParameters<typeof ReadonlyObjectParser>[1]
33+
asReadonlyObject = <O extends Object>(
34+
parse: ConstructorParameters<typeof ReadonlyObjectParser<O>>[1]
3535
) => new ReadonlyObjectParser(this.value, parse);
3636
}
3737

0 commit comments

Comments
 (0)