@nerd-bible/valio 0.1.4 → 0.1.5
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/codecs.d.ts +12 -0
- package/dist/codecs.d.ts.map +1 -0
- package/dist/codecs.js +42 -0
- package/dist/codecs.js.map +1 -0
- package/dist/containers.d.ts +57 -0
- package/dist/containers.d.ts.map +1 -0
- package/dist/containers.js +207 -0
- package/dist/containers.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/en.d.ts +2 -0
- package/dist/locales/en.d.ts.map +1 -0
- package/dist/locales/en.js +22 -0
- package/dist/locales/en.js.map +1 -0
- package/dist/pipe.d.ts +58 -0
- package/dist/pipe.d.ts.map +1 -0
- package/dist/pipe.js +144 -0
- package/dist/pipe.js.map +1 -0
- package/dist/primitives.d.ts +41 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +89 -0
- package/dist/primitives.js.map +1 -0
- package/package.json +7 -1
- package/.github/workflows/publish.yml +0 -28
- package/.github/workflows/test.yml +0 -14
- package/test/conllu.ts +0 -226
- package/test/gum.conllu +0 -66
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -1
package/dist/codecs.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context, Pipe, Result } from "./pipe.ts";
|
|
2
|
+
import * as p from "./primitives.ts";
|
|
3
|
+
export declare function custom<I, O>(input: Pipe<I, any>, output: Pipe<any, O>, codec: {
|
|
4
|
+
encode?(input: O, ctx: Context): Result<I>;
|
|
5
|
+
decode?(output: I, ctx: Context): Result<O>;
|
|
6
|
+
}): Pipe<I, O>;
|
|
7
|
+
export declare function number(parser?: (string: string) => number): p.Comparable<string | number | null | undefined, number>;
|
|
8
|
+
export declare function boolean(opts: {
|
|
9
|
+
true?: RegExp;
|
|
10
|
+
false?: RegExp;
|
|
11
|
+
}): Pipe<any, boolean>;
|
|
12
|
+
//# sourceMappingURL=codecs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../src/codecs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAC;AAErC,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAC1B,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EACnB,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EACpB,KAAK,EAAE;IACN,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;CAC5C,GACC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAMZ;AAED,wBAAgB,MAAM,CACrB,MAAM,6BAAoB,GACxB,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,CAAC,CAc1D;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAerB"}
|
package/dist/codecs.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as p from "./primitives.js";
|
|
2
|
+
export function custom(input, output, codec) {
|
|
3
|
+
const res = output.clone();
|
|
4
|
+
res.i = input.i.clone();
|
|
5
|
+
res.i.transform = codec.decode;
|
|
6
|
+
res.o.transform = codec.encode;
|
|
7
|
+
return res;
|
|
8
|
+
}
|
|
9
|
+
export function number(parser = Number.parseFloat) {
|
|
10
|
+
return custom(p.any(), p.number(), {
|
|
11
|
+
decode(input, ctx) {
|
|
12
|
+
if (typeof input === "number")
|
|
13
|
+
return { success: true, output: input };
|
|
14
|
+
if (!input || input.toLowerCase() === "nan")
|
|
15
|
+
return { success: true, output: Number.NaN };
|
|
16
|
+
const output = parser(input);
|
|
17
|
+
if (!Number.isNaN(output))
|
|
18
|
+
return { success: true, output };
|
|
19
|
+
ctx.pushErrorFmt("coerce", input, { expected: "number" });
|
|
20
|
+
return { success: false, errors: ctx.errors };
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function boolean(opts) {
|
|
25
|
+
return custom(p.any(), p.boolean(), {
|
|
26
|
+
decode(input, ctx) {
|
|
27
|
+
if (typeof input === "boolean")
|
|
28
|
+
return { success: true, output: input };
|
|
29
|
+
if (typeof input === "string") {
|
|
30
|
+
if (opts.true?.test(input))
|
|
31
|
+
return { success: true, output: true };
|
|
32
|
+
if (opts.false?.test(input))
|
|
33
|
+
return { success: true, output: false };
|
|
34
|
+
}
|
|
35
|
+
if (typeof input === "number")
|
|
36
|
+
return { success: true, output: Boolean(input) };
|
|
37
|
+
ctx.pushErrorFmt("coerce", input, { expected: "boolean" });
|
|
38
|
+
return { success: false, errors: ctx.errors };
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=codecs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs.js","sourceRoot":"","sources":["../src/codecs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAC;AAErC,MAAM,UAAU,MAAM,CACrB,KAAmB,EACnB,MAAoB,EACpB,KAGC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,EAAS,CAAC;IAClC,GAAG,CAAC,CAAC,GAAG,KAAK,C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AAK,SAAS;gBAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YACxE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC/B,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;oBAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;gBACnE,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC;oBAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YACtE,CAAC;YACD,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAC5B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAElD,GAAG,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;YAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;QAC/C,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Input, Output, Result } from "./pipe.ts";
|
|
2
|
+
import { Context, Pipe } from "./pipe.ts";
|
|
3
|
+
import * as p from "./primitives.ts";
|
|
4
|
+
declare class ValioArray<T> extends p.Arrayish<any[], T[]> {
|
|
5
|
+
element: Pipe<any, T>;
|
|
6
|
+
static typeCheck(v: any): v is any[];
|
|
7
|
+
constructor(element: Pipe<any, T>);
|
|
8
|
+
}
|
|
9
|
+
export declare function array<T>(element: Pipe<any, T>): ValioArray<T>;
|
|
10
|
+
declare class ValioRecord<K extends PropertyKey, V> extends Pipe<Record<any, any>, Record<K, V>> {
|
|
11
|
+
keyPipe: Pipe<any, K>;
|
|
12
|
+
valPipe: Pipe<any, V>;
|
|
13
|
+
static typeCheck(v: any): v is Record<any, any>;
|
|
14
|
+
constructor(keyPipe: Pipe<any, K>, valPipe: Pipe<any, V>);
|
|
15
|
+
}
|
|
16
|
+
export declare function record<K extends PropertyKey, V>(keyPipe: Pipe<any, K>, valPipe: Pipe<any, V>): ValioRecord<K, V>;
|
|
17
|
+
declare class Union<T extends Readonly<Pipe[]>> extends Pipe<Output<T[number]>, Output<T[number]>> {
|
|
18
|
+
options: T;
|
|
19
|
+
constructor(options: T);
|
|
20
|
+
}
|
|
21
|
+
export declare function union<T extends Readonly<Pipe[]>>(options: T): Union<T>;
|
|
22
|
+
type ObjectOutput<Shape extends Record<string, Pipe<any, any>>> = {
|
|
23
|
+
[K in keyof Shape]: Output<Shape[K]>;
|
|
24
|
+
};
|
|
25
|
+
type Mask<Keys extends PropertyKey> = {
|
|
26
|
+
[K in Keys]?: true;
|
|
27
|
+
};
|
|
28
|
+
type Identity<T> = T;
|
|
29
|
+
type Flatten<T> = Identity<{
|
|
30
|
+
[k in keyof T]: T[k];
|
|
31
|
+
}>;
|
|
32
|
+
type Extend<A extends Record<any, any>, B extends Record<any, any>> = Flatten<keyof A & keyof B extends never ? A & B : {
|
|
33
|
+
[K in keyof A as K extends keyof B ? never : K]: A[K];
|
|
34
|
+
} & {
|
|
35
|
+
[K in keyof B]: B[K];
|
|
36
|
+
}>;
|
|
37
|
+
export declare class ValioObject<Shape extends Record<any, Pipe<any, any>>> extends Pipe<Record<any, any>, ObjectOutput<Shape>> {
|
|
38
|
+
shape: Shape;
|
|
39
|
+
isLoose: boolean;
|
|
40
|
+
static typeCheck(v: any): v is Record<any, any>;
|
|
41
|
+
constructor(shape: Shape, isLoose: boolean);
|
|
42
|
+
clone(): this;
|
|
43
|
+
protected transformInput(data: object, ctx: Context): Result<ObjectOutput<Shape>>;
|
|
44
|
+
protected typeCheckOutput(v: any): v is ObjectOutput<Shape>;
|
|
45
|
+
pick<M extends Mask<keyof Shape>>(mask: M): ValioObject<Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>>;
|
|
46
|
+
omit<M extends Mask<keyof Shape>>(mask: M): ValioObject<Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>>;
|
|
47
|
+
partial<M extends Mask<keyof Shape>>(mask: M): ValioObject<{
|
|
48
|
+
[k in keyof Shape]: k extends keyof M ? Pipe<Input<Shape[k]>, Output<Shape[k]> | undefined> : Shape[k];
|
|
49
|
+
}>;
|
|
50
|
+
extend<T extends Record<any, Pipe<any, any>>>(shape: T): ValioObject<Extend<Shape, T>>;
|
|
51
|
+
loose<T = any>(isLoose?: boolean): ValioObject<Shape & {
|
|
52
|
+
[k: string]: Pipe<T, T>;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
export declare function object<Shape extends Record<any, Pipe<any, any>>>(shape: Shape, loose?: boolean): ValioObject<Shape>;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=containers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containers.d.ts","sourceRoot":"","sources":["../src/containers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,EAAY,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAC;AAErC,cAAM,UAAU,CAAC,CAAC,CAAE,SAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC;IACjD,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAEtB,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,GAAG,EAAE;gBAIxB,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;CA+BjC;AACD,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EA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UAAO,GACZ,WAAW,CAAC,KAAK,GAAG;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;KAAE,CAAC;CAKnD;AACD,wBAAgB,MAAM,CAAC,KAAK,SAAS,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAC/D,KAAK,EAAE,KAAK,EACZ,KAAK,UAAQ,GACX,WAAW,CAAC,KAAK,CAAC,CAEpB"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Context, HalfPipe, Pipe } from "./pipe.js";
|
|
2
|
+
import * as p from "./primitives.js";
|
|
3
|
+
class ValioArray extends p.Arrayish {
|
|
4
|
+
element;
|
|
5
|
+
static typeCheck(v) {
|
|
6
|
+
return Array.isArray(v);
|
|
7
|
+
}
|
|
8
|
+
constructor(element) {
|
|
9
|
+
super(new HalfPipe("array", ValioArray.typeCheck, function parseAnyArr(input, ctx) {
|
|
10
|
+
const output = new Array(input.length);
|
|
11
|
+
let success = true;
|
|
12
|
+
const length = ctx.jsonPath.length;
|
|
13
|
+
for (let i = 0; i < input.length; i++) {
|
|
14
|
+
ctx.jsonPath[length] = i.toString();
|
|
15
|
+
const decoded = element.decode(input[i], ctx);
|
|
16
|
+
if (decoded.success)
|
|
17
|
+
output[i] = decoded.output;
|
|
18
|
+
else
|
|
19
|
+
success = false;
|
|
20
|
+
}
|
|
21
|
+
ctx.jsonPath.length = length;
|
|
22
|
+
if (!success)
|
|
23
|
+
return { success, errors: ctx.errors };
|
|
24
|
+
return { success, output };
|
|
25
|
+
}), new HalfPipe(`array<${element.o.name}>`, function isArrT(v) {
|
|
26
|
+
if (!ValioArray.typeCheck(v))
|
|
27
|
+
return false;
|
|
28
|
+
for (const e of v)
|
|
29
|
+
if (!element.o.typeCheck(e))
|
|
30
|
+
return false;
|
|
31
|
+
return true;
|
|
32
|
+
}));
|
|
33
|
+
this.element = element;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function array(element) {
|
|
37
|
+
return new ValioArray(element);
|
|
38
|
+
}
|
|
39
|
+
class ValioRecord extends Pipe {
|
|
40
|
+
keyPipe;
|
|
41
|
+
valPipe;
|
|
42
|
+
static typeCheck(v) {
|
|
43
|
+
return Object.prototype.toString.call(v) === "[object Object]";
|
|
44
|
+
}
|
|
45
|
+
constructor(keyPipe, valPipe) {
|
|
46
|
+
super(new HalfPipe("object", ValioRecord.typeCheck, function anyToRecordKV(input, ctx) {
|
|
47
|
+
const output = {};
|
|
48
|
+
let success = true;
|
|
49
|
+
const length = ctx.jsonPath.length;
|
|
50
|
+
for (const key in input) {
|
|
51
|
+
ctx.jsonPath[length] = key;
|
|
52
|
+
const decodedKey = keyPipe.decode(key, ctx);
|
|
53
|
+
if (decodedKey.success) {
|
|
54
|
+
const decodedVal = valPipe.decode(input[key], ctx);
|
|
55
|
+
if (decodedVal.success) {
|
|
56
|
+
output[decodedKey.output] = decodedVal.output;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
success = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
success = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
ctx.jsonPath.length = length;
|
|
67
|
+
if (!success)
|
|
68
|
+
return { success, errors: ctx.errors };
|
|
69
|
+
return { success, output };
|
|
70
|
+
}), new HalfPipe(`record<${keyPipe.o.name},${valPipe.o.name}>`, function recordCheckV(v) {
|
|
71
|
+
if (!ValioRecord.typeCheck(v))
|
|
72
|
+
return false;
|
|
73
|
+
for (const k in v) {
|
|
74
|
+
// Keys will always be strings.
|
|
75
|
+
// if (!keyPipe.o.typeCheck(k)) return false;
|
|
76
|
+
if (!valPipe.o.typeCheck(v[k]))
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}));
|
|
81
|
+
this.keyPipe = keyPipe;
|
|
82
|
+
this.valPipe = valPipe;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function record(keyPipe, valPipe) {
|
|
86
|
+
return new ValioRecord(keyPipe, valPipe);
|
|
87
|
+
}
|
|
88
|
+
class Union extends Pipe {
|
|
89
|
+
options;
|
|
90
|
+
constructor(options) {
|
|
91
|
+
const name = options.map((o) => o.o.name).join("|");
|
|
92
|
+
super(new HalfPipe(name, function isUnionType(v) {
|
|
93
|
+
for (const f of options)
|
|
94
|
+
if (f.i.typeCheck(v))
|
|
95
|
+
return true;
|
|
96
|
+
return false;
|
|
97
|
+
}, (data, ctx) => {
|
|
98
|
+
// Throw away errors since we expect them.
|
|
99
|
+
const newCtx = new Context();
|
|
100
|
+
newCtx.pushErrorFmt = () => { };
|
|
101
|
+
newCtx.pushError = () => { };
|
|
102
|
+
for (const f of options) {
|
|
103
|
+
const decoded = f.decode(data, newCtx);
|
|
104
|
+
if (decoded.success)
|
|
105
|
+
return decoded;
|
|
106
|
+
}
|
|
107
|
+
// Sad path -- do again with real ctx to gather errors.
|
|
108
|
+
for (const f of options)
|
|
109
|
+
f.decode(data, ctx);
|
|
110
|
+
return { success: false, errors: ctx.errors };
|
|
111
|
+
}), new HalfPipe(name, function isUnionType2(v) {
|
|
112
|
+
for (const f of options)
|
|
113
|
+
if (f.o.typeCheck(v))
|
|
114
|
+
return true;
|
|
115
|
+
return false;
|
|
116
|
+
}));
|
|
117
|
+
this.options = options;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function union(options) {
|
|
121
|
+
return new Union(options);
|
|
122
|
+
}
|
|
123
|
+
export class ValioObject extends Pipe {
|
|
124
|
+
shape;
|
|
125
|
+
isLoose;
|
|
126
|
+
static typeCheck(v) {
|
|
127
|
+
return typeof v === "object";
|
|
128
|
+
}
|
|
129
|
+
constructor(shape, isLoose) {
|
|
130
|
+
super(new HalfPipe("object", ValioObject.typeCheck, (data, ctx) => this.transformInput(data, ctx)), new HalfPipe(`{${Object.entries(shape)
|
|
131
|
+
.map(([k, v]) => `${k}: ${v.o.name}`)
|
|
132
|
+
.join(",")}}`, (v) => this.typeCheckOutput(v)));
|
|
133
|
+
this.shape = shape;
|
|
134
|
+
this.isLoose = isLoose;
|
|
135
|
+
}
|
|
136
|
+
clone() {
|
|
137
|
+
return new ValioObject(this.shape, this.isLoose);
|
|
138
|
+
}
|
|
139
|
+
transformInput(data, ctx) {
|
|
140
|
+
const output = this.isLoose ? data : {};
|
|
141
|
+
let success = true;
|
|
142
|
+
const length = ctx.jsonPath.length;
|
|
143
|
+
// Always expect the shape since that's what typescript does.
|
|
144
|
+
for (const p in this.shape) {
|
|
145
|
+
ctx.jsonPath[length] = p;
|
|
146
|
+
const decoded = this.shape[p].decode(data[p], ctx);
|
|
147
|
+
if (decoded.success)
|
|
148
|
+
output[p] = decoded.output;
|
|
149
|
+
else {
|
|
150
|
+
success = false;
|
|
151
|
+
delete output[p];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
ctx.jsonPath.length = length;
|
|
155
|
+
if (!success)
|
|
156
|
+
return { success, errors: ctx.errors };
|
|
157
|
+
return { success, output: output };
|
|
158
|
+
}
|
|
159
|
+
typeCheckOutput(v) {
|
|
160
|
+
if (!ValioObject.typeCheck(v))
|
|
161
|
+
return false;
|
|
162
|
+
for (const s in this.shape)
|
|
163
|
+
if (!this.shape[s].o.typeCheck(v[s]))
|
|
164
|
+
return false;
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
pick(mask) {
|
|
168
|
+
const next = this.clone();
|
|
169
|
+
for (const k in next.shape) {
|
|
170
|
+
if (!mask[k])
|
|
171
|
+
delete next.shape[k];
|
|
172
|
+
}
|
|
173
|
+
return next;
|
|
174
|
+
}
|
|
175
|
+
omit(mask) {
|
|
176
|
+
const next = this.clone();
|
|
177
|
+
for (const k in next.shape) {
|
|
178
|
+
if (mask[k])
|
|
179
|
+
delete next.shape[k];
|
|
180
|
+
}
|
|
181
|
+
return next;
|
|
182
|
+
}
|
|
183
|
+
partial(mask) {
|
|
184
|
+
const next = this.clone();
|
|
185
|
+
for (const k in next.shape) {
|
|
186
|
+
if (mask[k]) {
|
|
187
|
+
// @ts-expect-error
|
|
188
|
+
next.shape[k] = union([next.shape[k], p.undefined()]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return next;
|
|
192
|
+
}
|
|
193
|
+
extend(shape) {
|
|
194
|
+
const next = this.clone();
|
|
195
|
+
Object.assign(next.shape, shape);
|
|
196
|
+
return next;
|
|
197
|
+
}
|
|
198
|
+
loose(isLoose = true) {
|
|
199
|
+
const next = this.clone();
|
|
200
|
+
next.isLoose = isLoose;
|
|
201
|
+
return next;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export function object(shape, loose = false) {
|
|
205
|
+
return new ValioObject(shape, loose);
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=containers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containers.js","sourceRoot":"","sources":["../src/containers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAC;AAErC,MAAM,UAAc,SAAQ,CAAC,CAAC,QAAoB;IACjD,OAAO,CAAe;IAEtB,MAAM,CAAC,SAAS,CAAC,CAAM;QACtB,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IAED,YAAY,OAAqB;QAChC,KAAK,CACJ,IAAI,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,SAAS,EAAE,SAAS,WAAW,CAC/D,KAAY,EACZ,GAAY;YAEZ,MAAM,MAAM,GAAG,IAAI,KAAK,CAAI,KAAK,CAAC,MAAM,CAAC,CAAC;YAC1C,IAAI,OAAO,GAAG,IAAI,CAAC;YAEnB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;YACnC,KAAK,I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AAC,KAAK,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACb,mBAAmB;gBACnB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YACvD,CAAC;QACF,CAAC;QACD,OAAO,IAAW,CAAC;IACpB,CAAC;IAED,MAAM,CACL,KAAQ;QAER,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACjC,OAAO,IAAW,CAAC;IACpB,CAAC;IAED,KAAK,CACJ,OAAO,GAAG,IAAI;QAEd,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAW,CAAC;IACpB,CAAC;CACD;AACD,MAAM,UAAU,MAAM,CACrB,KAAY,EACZ,KAAK,GAAG,KAAK;IAEb,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/locales/en.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM,CAG5E"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const templates = {
|
|
2
|
+
gt: "must be > {$n}",
|
|
3
|
+
lt: "must be < {$n}",
|
|
4
|
+
gte: "must be >= {$n}",
|
|
5
|
+
lte: "must be <= {$n}",
|
|
6
|
+
eq: "must be {$n}",
|
|
7
|
+
minLength: "must have length <= {$n}",
|
|
8
|
+
maxLength: "must have length >= {$n}",
|
|
9
|
+
regex: "must match {$regex}",
|
|
10
|
+
type: "not type {$expected}",
|
|
11
|
+
coerce: "could not coerce to {$expected}",
|
|
12
|
+
};
|
|
13
|
+
function fmt(template, props) {
|
|
14
|
+
// You could use something like
|
|
15
|
+
// [MessageFormat](https://messageformat.unicode.org/) here.
|
|
16
|
+
return template.replace(/{\$(.*?)}/g, (_, g) => props[g]);
|
|
17
|
+
}
|
|
18
|
+
export default function format(name, props) {
|
|
19
|
+
const template = templates[name];
|
|
20
|
+
return template ? fmt(template, props) : `TODO: add template for ${name}`;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=en.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/locales/en.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAA2B;IACzC,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,gBAAgB;IACpB,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,iBAAiB;IACtB,EAAE,EAAE,cAAc;IAClB,SAAS,EAAE,0BAA0B;IACrC,SAAS,EAAE,0BAA0B;IACrC,KAAK,EAAE,qBAAqB;IAC5B,IAAI,EAAE,sBAAsB;IAC5B,MAAM,EAAE,iCAAiC;CACzC,CAAC;AAEF,SAAS,GAAG,CAAC,QAAgB,EAAE,KAAuB;IACrD,+BAA+B;IAC/B,4DAA4D;IAC5D,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAY,EAAE,KAAuB;IACnE,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,0BAA0B,IAAI,EAAE,CAAC;AAC3E,CAAC"}
|
package/dist/pipe.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type Error = {
|
|
2
|
+
input: any;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
export type Errors = {
|
|
6
|
+
[inputPath: string]: Error[];
|
|
7
|
+
};
|
|
8
|
+
export type Result<T> = {
|
|
9
|
+
success: true;
|
|
10
|
+
output: T;
|
|
11
|
+
} | {
|
|
12
|
+
success: false;
|
|
13
|
+
errors: any;
|
|
14
|
+
};
|
|
15
|
+
interface Check<T> {
|
|
16
|
+
valid(data: T, ctx: Context): boolean;
|
|
17
|
+
name: string;
|
|
18
|
+
props: Record<any, any>;
|
|
19
|
+
}
|
|
20
|
+
export declare class HalfPipe<I, O = never> {
|
|
21
|
+
name: string;
|
|
22
|
+
typeCheck: (v: any) => v is I;
|
|
23
|
+
transform?: (v: I, ctx: Context) => Result<O>;
|
|
24
|
+
/** Checks to run after type check */
|
|
25
|
+
checks: Check<I>[];
|
|
26
|
+
constructor(name: string, typeCheck: (v: any) => v is I, transform?: (v: I, ctx: Context) => Result<O>, checks?: Check<I>[]);
|
|
27
|
+
clone(): HalfPipe<I, O>;
|
|
28
|
+
}
|
|
29
|
+
/** During encoding, decoding, or validation. */
|
|
30
|
+
export declare class Context {
|
|
31
|
+
jsonPath: (string | number)[];
|
|
32
|
+
errors: Errors;
|
|
33
|
+
errorFmt(name: string, props: Record<any, any>): any;
|
|
34
|
+
clone(): Context;
|
|
35
|
+
pushError(error: Error): void;
|
|
36
|
+
pushErrorFmt(name: string, input: any, props: Record<any, any>): void;
|
|
37
|
+
run<I, O>(input: any, halfPipe: HalfPipe<I, O>): Result<I>;
|
|
38
|
+
}
|
|
39
|
+
export declare class Pipe<I = any, O = any> {
|
|
40
|
+
i: HalfPipe<I, O>;
|
|
41
|
+
o: HalfPipe<O, I>;
|
|
42
|
+
constructor(i: HalfPipe<I, O>, o: HalfPipe<O, I>);
|
|
43
|
+
pipes: Pipe<any, any>[];
|
|
44
|
+
registry: Record<PropertyKey, any>;
|
|
45
|
+
debug: boolean;
|
|
46
|
+
clone(): this;
|
|
47
|
+
refine(valid: (data: O, ctx: Context) => boolean, name: string, props?: Record<any, any>): this;
|
|
48
|
+
pipe<I2 extends O, O2>(pipe: Pipe<I2, O2>): Pipe<I, O2>;
|
|
49
|
+
decodeAny(input: any, ctx?: Context): Result<O>;
|
|
50
|
+
decode(input: I, ctx?: Context): Result<O>;
|
|
51
|
+
encodeAny(output: any, ctx?: Context): Result<I>;
|
|
52
|
+
encode(output: O, ctx?: Context): Result<I>;
|
|
53
|
+
register(key: PropertyKey, value: any): this;
|
|
54
|
+
}
|
|
55
|
+
export type Input<T extends Pipe> = Parameters<T["decode"]>[0];
|
|
56
|
+
export type Output<T extends Pipe> = Parameters<T["encode"]>[0];
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=pipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe.d.ts","sourceRoot":"","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M,GAC1B,IAAI;IAMP,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;IAMvD,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,UAAgB,GAAG,MAAM,CAAC,CAAC,CAAC;IAmBrD,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,UAAgB,GAAG,MAAM,CAAC,CAAC,CAAC;IAIhD,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,UAAgB,GAAG,MAAM,CAAC,CAAC,CAAC;IAkBtD,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,UAAgB,GAAG,MAAM,CAAC,CAAC,CAAC;IAIjD,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;CAK5C;AAED,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/pipe.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import enFormat from "./locales/en.js";
|
|
2
|
+
function clone(obj) {
|
|
3
|
+
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
|
4
|
+
}
|
|
5
|
+
export class HalfPipe {
|
|
6
|
+
name;
|
|
7
|
+
typeCheck;
|
|
8
|
+
transform;
|
|
9
|
+
/** Checks to run after type check */
|
|
10
|
+
checks = [];
|
|
11
|
+
constructor(name, typeCheck, transform, checks = []) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.typeCheck = typeCheck;
|
|
14
|
+
this.transform = transform;
|
|
15
|
+
this.checks = checks;
|
|
16
|
+
}
|
|
17
|
+
clone() {
|
|
18
|
+
return new HalfPipe(this.name, this.typeCheck, this.transform, this.checks.slice());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** During encoding, decoding, or validation. */
|
|
22
|
+
export class Context {
|
|
23
|
+
jsonPath = [];
|
|
24
|
+
errors = {};
|
|
25
|
+
errorFmt(name, props) {
|
|
26
|
+
return enFormat(name, props);
|
|
27
|
+
}
|
|
28
|
+
clone() {
|
|
29
|
+
const res = new Context();
|
|
30
|
+
res.jsonPath = this.jsonPath.slice();
|
|
31
|
+
res.errors = { ...this.errors };
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
pushError(error) {
|
|
35
|
+
const key = `.${this.jsonPath.join(".")}`;
|
|
36
|
+
this.errors[key] ??= [];
|
|
37
|
+
this.errors[key].push(error);
|
|
38
|
+
}
|
|
39
|
+
pushErrorFmt(name, input, props) {
|
|
40
|
+
const message = this.errorFmt(name, props);
|
|
41
|
+
this.pushError({ input, message });
|
|
42
|
+
}
|
|
43
|
+
run(input, halfPipe) {
|
|
44
|
+
if (!halfPipe.typeCheck(input)) {
|
|
45
|
+
this.pushErrorFmt("type", input, { expected: halfPipe.name });
|
|
46
|
+
return { success: false, errors: this.errors };
|
|
47
|
+
}
|
|
48
|
+
let success = true;
|
|
49
|
+
for (const c of halfPipe.checks ?? []) {
|
|
50
|
+
if (!c.valid(input, this)) {
|
|
51
|
+
this.pushErrorFmt(c.name, input, c.props);
|
|
52
|
+
success = false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!success)
|
|
56
|
+
return { success, errors: this.errors };
|
|
57
|
+
return { success, output: input };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class Pipe {
|
|
61
|
+
i;
|
|
62
|
+
o;
|
|
63
|
+
constructor(i, o) {
|
|
64
|
+
this.i = i;
|
|
65
|
+
this.o = o;
|
|
66
|
+
}
|
|
67
|
+
pipes = [];
|
|
68
|
+
registry = {};
|
|
69
|
+
debug = false;
|
|
70
|
+
clone() {
|
|
71
|
+
const res = clone(this);
|
|
72
|
+
res.i = res.i.clone();
|
|
73
|
+
res.o = res.o.clone();
|
|
74
|
+
res.pipes = res.pipes.slice();
|
|
75
|
+
res.registry = { ...res.registry };
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
refine(valid, name, props = {}) {
|
|
79
|
+
const res = this.clone();
|
|
80
|
+
res.o.checks.push({ valid, name, props });
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
83
|
+
pipe(pipe) {
|
|
84
|
+
const res = this.clone();
|
|
85
|
+
res.pipes.push(pipe);
|
|
86
|
+
return res;
|
|
87
|
+
}
|
|
88
|
+
decodeAny(input, ctx = new Context()) {
|
|
89
|
+
// 1. Verify input
|
|
90
|
+
let res = ctx.run(input, this.i);
|
|
91
|
+
if (!res.success)
|
|
92
|
+
return res;
|
|
93
|
+
// 2. Transform input to output
|
|
94
|
+
if (this.i.transform) {
|
|
95
|
+
res = this.i.transform(res.output, ctx);
|
|
96
|
+
if (!res.success)
|
|
97
|
+
return res;
|
|
98
|
+
}
|
|
99
|
+
// 3. Verify output
|
|
100
|
+
res = ctx.run(res.output, this.o);
|
|
101
|
+
if (!res.success)
|
|
102
|
+
return res;
|
|
103
|
+
// 4. Next
|
|
104
|
+
for (const p of this.pipes) {
|
|
105
|
+
res = p.decode(res.output, ctx);
|
|
106
|
+
if (!res.success)
|
|
107
|
+
return res;
|
|
108
|
+
}
|
|
109
|
+
return res;
|
|
110
|
+
}
|
|
111
|
+
decode(input, ctx = new Context()) {
|
|
112
|
+
return this.decodeAny(input, ctx);
|
|
113
|
+
}
|
|
114
|
+
encodeAny(output, ctx = new Context()) {
|
|
115
|
+
// 1. Next
|
|
116
|
+
let res = { success: true, output };
|
|
117
|
+
for (let i = this.pipes.length - 1; i >= 0; i--) {
|
|
118
|
+
res = this.pipes[i].encodeAny(res.output, ctx);
|
|
119
|
+
if (!res.success)
|
|
120
|
+
return res;
|
|
121
|
+
}
|
|
122
|
+
// 2. Verify output
|
|
123
|
+
res = ctx.run(res.output, this.o);
|
|
124
|
+
if (!res.success)
|
|
125
|
+
return res;
|
|
126
|
+
// 3. Transform output to input
|
|
127
|
+
if (this.o.transform) {
|
|
128
|
+
res = this.o.transform(res.output, ctx);
|
|
129
|
+
if (!res.success)
|
|
130
|
+
return res;
|
|
131
|
+
}
|
|
132
|
+
// 4. Verify input
|
|
133
|
+
return ctx.run(res.output, this.i);
|
|
134
|
+
}
|
|
135
|
+
encode(output, ctx = new Context()) {
|
|
136
|
+
return this.encodeAny(output, ctx);
|
|
137
|
+
}
|
|
138
|
+
register(key, value) {
|
|
139
|
+
const res = this.clone();
|
|
140
|
+
res.registry[key] = value;
|
|
141
|
+
return res;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=pipe.js.map
|
package/dist/pipe.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../src/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAQvC,SAAS,KAAK,CAAI,GAAM;IACvB,OAAO,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAC1B,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC,CACrC,CAAC;AACH,CAAC;AAQD,MAAM,OAAO,QAAQ;IACpB,IAAI,CAAS;IACb,SAAS,CAAqB;IAC9B,SAAS,CAAqC;IAC9C,qCAAqC;IACrC,MAAM,GAAe,EAAE,CAAC;IAExB,YACC,IAAY,EACZ,SAA6B,EAC7B,SAA6C,EAC7C,SAAqB,EAAE;QAEvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAA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GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,GAAG,CAAC,OAAO;gBAAE,OAAO,GAAG,CAAC;QAC9B,CAAC;QACD,kBAAkB;QAClB,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,MAAS,EAAE,GAAG,GAAG,IAAI,OAAO,EAAE;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ,CAAC,GAAgB,EAAE,KAAU;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QACzB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC1B,OAAO,GAAG,CAAC;IACZ,CAAC;CACD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Pipe } from "./pipe.ts";
|
|
2
|
+
export declare function boolean(): Pipe<boolean, boolean>;
|
|
3
|
+
export declare function undefined(): Pipe<undefined, undefined>;
|
|
4
|
+
export declare function any(): Pipe<any, any>;
|
|
5
|
+
declare function null_(): Pipe<null, null>;
|
|
6
|
+
export { null_ as null };
|
|
7
|
+
export declare class Comparable<I, O> extends Pipe<I, O> {
|
|
8
|
+
gt(n: O): this;
|
|
9
|
+
gte(n: O): this;
|
|
10
|
+
lt(n: O): this;
|
|
11
|
+
lte(n: O): this;
|
|
12
|
+
eq(n: O): this;
|
|
13
|
+
}
|
|
14
|
+
declare class ValioNumber extends Comparable<number, number> {
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
17
|
+
export declare function number(): ValioNumber;
|
|
18
|
+
export declare class Arrayish<I, O extends {
|
|
19
|
+
length: number;
|
|
20
|
+
}> extends Pipe<I, O> {
|
|
21
|
+
minLength(n: number): this;
|
|
22
|
+
maxLength(n: number): this;
|
|
23
|
+
}
|
|
24
|
+
declare class ValioString extends Arrayish<string, string> {
|
|
25
|
+
constructor();
|
|
26
|
+
regex(re: RegExp): this;
|
|
27
|
+
}
|
|
28
|
+
export declare function string(): ValioString;
|
|
29
|
+
export type Lit = string | number | bigint | boolean | null | undefined;
|
|
30
|
+
declare class ValioLiteral<T extends Lit> extends Pipe<T, T> {
|
|
31
|
+
literal: T;
|
|
32
|
+
constructor(literal: T);
|
|
33
|
+
}
|
|
34
|
+
export declare function literal<T extends Lit>(literal: T): ValioLiteral<T>;
|
|
35
|
+
declare class ValioEnum<T extends Lit> extends Pipe<T, T> {
|
|
36
|
+
literals: readonly T[];
|
|
37
|
+
constructor(literals: readonly T[]);
|
|
38
|
+
}
|
|
39
|
+
declare function enum_<T extends Lit>(literals: readonly T[]): ValioEnum<T>;
|
|
40
|
+
export { enum_ as enum };
|
|
41
|
+
//# sourceMappingURL=primitives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../src/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAE,MAAM,WAAW,CAAC;AAO3C,wBAAgB,OAAO,2BAKtB;AAGD,wBAAgB,SAAS,+BAKxB;AAED,wBAAgB,GAAG,mBAElB;AAED,iBAAS,KAAK,qBAEb;AACD,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;AAEzB,qBAAa,UAAU,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/C,EAAE,CAAC,CAAC,EAAE,CAAC;IAGP,GAAG,CAAC,CAAC,EAAE,CAAC;IAGR,EAAE,CAAC,CAAC,EAAE,CAAC;IAGP,GAAG,CAAC,CAAC,EAAE,CAAC;IAGR,EAAE,CAAC,CAAC,EAAE,CAAC;CAGP;AAED,cAAM,WAAY,SAAQ,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;;CAKnD;AACD,wBAAgB,MAAM,gBAErB;AAED,qBAAa,QAAQ,CACpB,CAAC,EACD,CAAC,SAAS;IACT,MAAM,EAAE,MAAM,CAAC;CACf,CACA,SAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IACnB,SAAS,CAAC,CAAC,EAAE,MAAM;IAGnB,SAAS,CAAC,CAAC,EAAE,MAAM;CAGnB;AAED,cAAM,WAAY,SAAQ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;;IAMjD,KAAK,CAAC,EAAE,EAAE,MAAM;CAGhB;AACD,wBAAgB,MAAM,IAAI,WAAW,CAEpC;AAED,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAExE,cAAM,YAAY,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IACnD,OAAO,EAAE,CAAC,CAAC;gBAEC,OAAO,EAAE,CAAC;CAKtB;AACD,wBAAgB,OAAO,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,CAAC,mBAEhD;AAED,cAAM,SAAS,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IAChD,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;gBAEX,QAAQ,EAAE,SAAS,CAAC,EAAE;CAOlC;AACD,iBAAS,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAElE;AACD,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { HalfPipe, Pipe } from "./pipe.js";
|
|
2
|
+
function primitive(name, typeCheck) {
|
|
3
|
+
const half = new HalfPipe(name, typeCheck);
|
|
4
|
+
return new Pipe(half, half);
|
|
5
|
+
}
|
|
6
|
+
export function boolean() {
|
|
7
|
+
return primitive("boolean", (v) => typeof v === "boolean");
|
|
8
|
+
}
|
|
9
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: point of lib
|
|
10
|
+
export function undefined() {
|
|
11
|
+
return primitive("undefined", (v) => typeof v === "undefined");
|
|
12
|
+
}
|
|
13
|
+
export function any() {
|
|
14
|
+
return primitive("any", (_v) => true);
|
|
15
|
+
}
|
|
16
|
+
function null_() {
|
|
17
|
+
return primitive("null", (v) => v === null);
|
|
18
|
+
}
|
|
19
|
+
export { null_ as null };
|
|
20
|
+
export class Comparable extends Pipe {
|
|
21
|
+
gt(n) {
|
|
22
|
+
return this.refine((v) => v > n, "gt", { n });
|
|
23
|
+
}
|
|
24
|
+
gte(n) {
|
|
25
|
+
return this.refine((v) => v >= n, "gte", { n });
|
|
26
|
+
}
|
|
27
|
+
lt(n) {
|
|
28
|
+
return this.refine((v) => v < n, "lt", { n });
|
|
29
|
+
}
|
|
30
|
+
lte(n) {
|
|
31
|
+
return this.refine((v) => v <= n, "lte", { n });
|
|
32
|
+
}
|
|
33
|
+
eq(n) {
|
|
34
|
+
return this.refine((v) => v === n, "eq", { n });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class ValioNumber extends Comparable {
|
|
38
|
+
constructor() {
|
|
39
|
+
const half = new HalfPipe("number", (v) => typeof v === "number");
|
|
40
|
+
super(half, half);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function number() {
|
|
44
|
+
return new ValioNumber();
|
|
45
|
+
}
|
|
46
|
+
export class Arrayish extends Pipe {
|
|
47
|
+
minLength(n) {
|
|
48
|
+
return this.refine((v) => v.length >= n, "minLength", { n });
|
|
49
|
+
}
|
|
50
|
+
maxLength(n) {
|
|
51
|
+
return this.refine((v) => v.length <= n, "maxLength", { n });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class ValioString extends Arrayish {
|
|
55
|
+
constructor() {
|
|
56
|
+
const half = new HalfPipe("string", (v) => typeof v === "string");
|
|
57
|
+
super(half, half);
|
|
58
|
+
}
|
|
59
|
+
regex(re) {
|
|
60
|
+
return this.refine((v) => !!v.match(re), "regex", { regex: re.source });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function string() {
|
|
64
|
+
return new ValioString();
|
|
65
|
+
}
|
|
66
|
+
class ValioLiteral extends Pipe {
|
|
67
|
+
literal;
|
|
68
|
+
constructor(literal) {
|
|
69
|
+
const half = new HalfPipe(`${literal}`, (v) => v === literal);
|
|
70
|
+
super(half, half);
|
|
71
|
+
this.literal = literal;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function literal(literal) {
|
|
75
|
+
return new ValioLiteral(literal);
|
|
76
|
+
}
|
|
77
|
+
class ValioEnum extends Pipe {
|
|
78
|
+
literals;
|
|
79
|
+
constructor(literals) {
|
|
80
|
+
const half = new HalfPipe(`${literals.join(",")}`, (v) => literals.includes(v));
|
|
81
|
+
super(half, half);
|
|
82
|
+
this.literals = literals;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function enum_(literals) {
|
|
86
|
+
return new ValioEnum(literals);
|
|
87
|
+
}
|
|
88
|
+
export { enum_ as enum };
|
|
89
|
+
//# sourceMappingURL=primitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../src/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3C,SAAS,SAAS,CAAI,IAAY,EAAE,SAA2B;IAC9D,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3C,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,OAAO;IACtB,OAAO,SAAS,CACf,SAAS,EACT,CAAC,CAAC,EAAgB,EAAE,CAAC,OAAO,CAAC,KAAK,SAAS,CAC3C,CAAC;AACH,CA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|
12
|
-
jobs:
|
|
13
|
-
publish:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v4
|
|
18
|
-
with:
|
|
19
|
-
fetch-depth: 0
|
|
20
|
-
- uses: actions/setup-node@v6
|
|
21
|
-
with:
|
|
22
|
-
node-version: "lts/*"
|
|
23
|
-
registry-url: "https://registry.npmjs.org"
|
|
24
|
-
- run: npm install
|
|
25
|
-
- run: npm test
|
|
26
|
-
- run: npm run build
|
|
27
|
-
- run: npx -p @nerd-bible/config pkgWrite
|
|
28
|
-
- run: npm publish --verbose
|
package/test/conllu.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import * as z from "../src/index.ts";
|
|
4
|
-
import { test } from "node:test";
|
|
5
|
-
import expect from "expect";
|
|
6
|
-
|
|
7
|
-
const intId = z.codecs.number().gt(0);
|
|
8
|
-
const rowId = z.union([
|
|
9
|
-
// Normal integer like 1, 2
|
|
10
|
-
intId,
|
|
11
|
-
// Multiword token like 1-4 or 1.2-4.2
|
|
12
|
-
z.string().regex(/[1-9][0-9]*\.\d+-\d+\.\d+/),
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
const boolean = z.codecs.boolean({
|
|
16
|
-
true: /yes|true/,
|
|
17
|
-
false: /no|false/,
|
|
18
|
-
});
|
|
19
|
-
const primitive = z.union([z.string(), boolean, z.codecs.number()]);
|
|
20
|
-
|
|
21
|
-
function recordConllu(delims = { prop: "|", value: "=" }) {
|
|
22
|
-
return z.codecs.custom(z.string(), z.record(z.string(), primitive), {
|
|
23
|
-
decode(value: string, ctx: z.Context) {
|
|
24
|
-
let success = true;
|
|
25
|
-
const output: Record<string, z.Output<typeof primitive>> = {};
|
|
26
|
-
|
|
27
|
-
const length = ctx.jsonPath.length;
|
|
28
|
-
for (const cur of value.split(delims.prop)) {
|
|
29
|
-
// 14:nmod:into
|
|
30
|
-
const index = cur.indexOf(delims.value);
|
|
31
|
-
const k = index === -1 ? cur : cur.substring(0, index);
|
|
32
|
-
if (!k) continue;
|
|
33
|
-
const v = index === -1 ? "" : cur.substring(index + 1);
|
|
34
|
-
ctx.jsonPath[length] = k;
|
|
35
|
-
const decoded = primitive.decode(v, ctx);
|
|
36
|
-
if (decoded.success) output[k] = decoded.output;
|
|
37
|
-
else success = false;
|
|
38
|
-
}
|
|
39
|
-
ctx.jsonPath.length = length;
|
|
40
|
-
|
|
41
|
-
if (!success) return { success, errors: ctx.errors };
|
|
42
|
-
return { success, output };
|
|
43
|
-
},
|
|
44
|
-
encode(v: Record<string, z.Output<typeof primitive>>) {
|
|
45
|
-
const entries = Object.entries(v);
|
|
46
|
-
if (!entries.length) return { success: true, output: "_" };
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
success: true,
|
|
50
|
-
output: entries
|
|
51
|
-
.map(([k, v]) => `${k}${delims.value}${v}`)
|
|
52
|
-
.join(delims.prop),
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const word = z.object({
|
|
59
|
-
id: rowId,
|
|
60
|
-
form: z.string(),
|
|
61
|
-
lemma: z.string(),
|
|
62
|
-
upos: z.string(),
|
|
63
|
-
xpos: z.string(),
|
|
64
|
-
feats: recordConllu(),
|
|
65
|
-
head: z.codecs.number(),
|
|
66
|
-
deprel: z.string(),
|
|
67
|
-
deps: recordConllu({ prop: "|", value: ":" }),
|
|
68
|
-
//.pipe(z.record(z.codecs.number().gte(0), primitive)),
|
|
69
|
-
misc: recordConllu(),
|
|
70
|
-
});
|
|
71
|
-
const columns = Object.keys(word.shape) as (keyof z.Output<typeof word>)[];
|
|
72
|
-
|
|
73
|
-
const wordConllu = z.codecs.custom(z.string(), word, {
|
|
74
|
-
decode(v, ctx) {
|
|
75
|
-
const split = v
|
|
76
|
-
.split("\t")
|
|
77
|
-
// spec is unclear what a missing _ means
|
|
78
|
-
// the _ are there for readability in editors that don't show whitespace
|
|
79
|
-
.map((v) => (v === "_" ? "" : v));
|
|
80
|
-
|
|
81
|
-
const res = {} as any;
|
|
82
|
-
for (let i = 0; i < columns.length; i++)
|
|
83
|
-
res[columns[i] as (typeof columns)[number]] = split[i];
|
|
84
|
-
|
|
85
|
-
return word.decode(res, ctx);
|
|
86
|
-
},
|
|
87
|
-
encode(value) {
|
|
88
|
-
let output = "";
|
|
89
|
-
for (const c of columns) {
|
|
90
|
-
const v = value[c];
|
|
91
|
-
if (v === "") output += "_";
|
|
92
|
-
else {
|
|
93
|
-
const encoded = word.shape[c].encode(v as never);
|
|
94
|
-
if (!encoded.success) return encoded;
|
|
95
|
-
output += encoded.output;
|
|
96
|
-
}
|
|
97
|
-
if (c !== "misc") output += "\t";
|
|
98
|
-
}
|
|
99
|
-
return { success: true, output };
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const headers = z.record(z.string(), z.union([z.string(), z.undefined()])).pipe(
|
|
104
|
-
z
|
|
105
|
-
.object({
|
|
106
|
-
sent_id: z.string().minLength(1),
|
|
107
|
-
text: z.string().minLength(1),
|
|
108
|
-
})
|
|
109
|
-
.loose(),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const headerPrefix = "# ";
|
|
113
|
-
const headersConllu = z.codecs.custom(z.string(), headers, {
|
|
114
|
-
decode(str, ctx) {
|
|
115
|
-
const kvs: Record<string, string | undefined> = {};
|
|
116
|
-
const lines = str.split(/\r?\n/);
|
|
117
|
-
for (let line of lines) {
|
|
118
|
-
line = line.substring(headerPrefix.length);
|
|
119
|
-
const i = line.indexOf("=");
|
|
120
|
-
if (i === -1) {
|
|
121
|
-
kvs[line] = undefined;
|
|
122
|
-
} else {
|
|
123
|
-
kvs[line.substring(0, i).trim()] = line.substring(i + 1).trim();
|
|
124
|
-
}
|
|
125
|
-
(ctx.jsonPath[0] as number) += 1;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return headers.decode(kvs);
|
|
129
|
-
},
|
|
130
|
-
encode(obj) {
|
|
131
|
-
let output = "";
|
|
132
|
-
for (const k in obj) {
|
|
133
|
-
output += `# ${k}`;
|
|
134
|
-
if (obj[k] != null) output += ` = ${obj[k]}`;
|
|
135
|
-
output += "\n";
|
|
136
|
-
}
|
|
137
|
-
return { success: true, output };
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const sentence = z.object({ headers, words: z.array(word) });
|
|
142
|
-
const sentenceConllu = z.codecs.custom(z.string(), sentence, {
|
|
143
|
-
decode(str, ctx) {
|
|
144
|
-
const headersEnd = str.match(/^[^#]/m);
|
|
145
|
-
const output: z.Output<typeof sentence> = {
|
|
146
|
-
headers: {} as any,
|
|
147
|
-
words: [],
|
|
148
|
-
};
|
|
149
|
-
if (headersEnd?.index) {
|
|
150
|
-
const headerSection = str.substring(0, headersEnd.index - 1);
|
|
151
|
-
str = str.substring(headersEnd.index);
|
|
152
|
-
const decoded = headersConllu.decode(headerSection, ctx);
|
|
153
|
-
if (!decoded.success) return decoded;
|
|
154
|
-
output.headers = decoded.output;
|
|
155
|
-
}
|
|
156
|
-
const lines = str.split(/\r?\n/);
|
|
157
|
-
for (const line of lines) {
|
|
158
|
-
if (line) {
|
|
159
|
-
const decoded = wordConllu.decode(line, ctx);
|
|
160
|
-
if (!decoded.success) return decoded;
|
|
161
|
-
output.words.push(decoded.output);
|
|
162
|
-
}
|
|
163
|
-
(ctx.jsonPath[0] as number) += 1;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return { success: true, output };
|
|
167
|
-
},
|
|
168
|
-
encode(sentence) {
|
|
169
|
-
const h = headersConllu.encode(sentence.headers!);
|
|
170
|
-
if (!h.success) return h;
|
|
171
|
-
let output = h.output;
|
|
172
|
-
for (const w of sentence.words!) {
|
|
173
|
-
const encoded = wordConllu.encode(w);
|
|
174
|
-
if (!encoded.success) return encoded;
|
|
175
|
-
output += encoded.output;
|
|
176
|
-
output += "\n";
|
|
177
|
-
}
|
|
178
|
-
return { success: true, output: output.trimEnd() };
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Makes sure syntax is followed and required fields are included.
|
|
183
|
-
const normal = z.codecs.custom(z.string(), z.array(sentence), {
|
|
184
|
-
decode(str, ctx) {
|
|
185
|
-
const output: z.Output<typeof sentence>[] = [];
|
|
186
|
-
const split = str.split(/\r?\n\r?\n/);
|
|
187
|
-
ctx.jsonPath[0] = 1;
|
|
188
|
-
for (const s of split) {
|
|
189
|
-
const decoded = sentenceConllu.decode(s, ctx);
|
|
190
|
-
if (!decoded.success) return decoded;
|
|
191
|
-
output.push(decoded.output);
|
|
192
|
-
ctx.jsonPath[0] += 2;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return { success: true, output };
|
|
196
|
-
},
|
|
197
|
-
encode(sentences, ctx) {
|
|
198
|
-
let output = "";
|
|
199
|
-
for (const s of sentences) {
|
|
200
|
-
const encoded = sentenceConllu.encode(s, ctx);
|
|
201
|
-
if (!encoded.success) return encoded;
|
|
202
|
-
output += encoded.output;
|
|
203
|
-
output += "\n\n";
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return { success: true, output: output.trimEnd() };
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test("parses and encodes gum", () => {
|
|
211
|
-
// const decoded = wordConllu.decode(
|
|
212
|
-
// "1 In in ADP IN _ 0 case 3:foo Verse=1|SourceMap=1",
|
|
213
|
-
// );
|
|
214
|
-
// if (decoded.success) {
|
|
215
|
-
// console.dir(decoded.output, { depth: null });
|
|
216
|
-
// console.log(wordConllu.encode(decoded.output).output)
|
|
217
|
-
// }
|
|
218
|
-
|
|
219
|
-
const text = readFileSync(join(import.meta.dirname, "gum.conllu"), "utf8");
|
|
220
|
-
const parsed = normal.decode(text);
|
|
221
|
-
expect(parsed.errors).toBeUndefined();
|
|
222
|
-
if (parsed.success) {
|
|
223
|
-
const reencoded = normal.encode(parsed.output);
|
|
224
|
-
expect(reencoded.errors).toBeUndefined();
|
|
225
|
-
}
|
|
226
|
-
});
|
package/test/gum.conllu
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# newdoc id = GUM_academic_exposure
|
|
2
|
-
# global.Entity = GRP-etype-infstat-salience-centering-minspan-link-identity
|
|
3
|
-
# meta::author = Kara Morgan-Short, Ingrid Finger, Sarah Grey, Michael T. Ullman
|
|
4
|
-
# meta::dateCollected = 2018-09-11
|
|
5
|
-
# meta::dateCreated = 2012-03-28
|
|
6
|
-
# meta::dateModified = 2012-03-28
|
|
7
|
-
# meta::genre = academic
|
|
8
|
-
# meta::salientEntities = 3 (5*), 56 (3*), 7 (2), 12 (2), 41 (2), 42 (2), 43 (2), 53 (2), 62 (2), 89 (2), 2 (1), 44 (1), 52 (1), 91 (1), 96 (1), 98 (1*), 116 (1)
|
|
9
|
-
# meta::sourceURL = https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0032974
|
|
10
|
-
# meta::speakerCount = 0
|
|
11
|
-
# meta::summary1 = (human1) This study shows that limited exposure to a second language (L2) after it is no longer being actively used generally causes attrition of L2 competence.
|
|
12
|
-
# meta::summary2 = (human2) Investigated the trends of six studies examining L2 possible attrition in classroom learned vs. immersion learned participants over time.
|
|
13
|
-
# meta::summary3 = (human3) Before reviewing the results of six similar studies, this paper presents a study that examines if a substantial period of no exposure following second language (L2) training leads to decreased proficiency and/or less native-like processes in adult learners, as well as if the outcome is influenced by classroom-like versus immersion-like contexts.
|
|
14
|
-
# meta::summary4 = (human4) This study tests the effect of limited exposure to second language after training on the neurocognition of L2 grammar in adult learners and describes previous studies on this topic that showed that in some cases limited exposure leads to attrition of L2 knowledge, but in other cases, there is either no attrition or even a gain in L2 performance.
|
|
15
|
-
# meta::summary5 = (human5) This section of a paper introduces the paper’s goal of examining the effect of substantial periods of no exposure on the neurocognition of adult-learned second language (L2) grammar, and discusses previous research findings on the effect of various periods of limited exposure following L2 training on L2 performance or knowledge.
|
|
16
|
-
# meta::title = Second Language Processing Shows Increased Native-Like Neural Responses after Months of No Exposure
|
|
17
|
-
# newpar
|
|
18
|
-
# newpar_block = head (1 s)
|
|
19
|
-
# sent_id = GUM_academic_exposure-1
|
|
20
|
-
# s_type = frag
|
|
21
|
-
# s_prominence = 2
|
|
22
|
-
# transition = establishment
|
|
23
|
-
# text = Introduction
|
|
24
|
-
1 Introduction introduction NOUN NN Number=Sing 0 root 0:root Discourse=organization-heading:1->29:3:grf-ly-|Entity=(1-abstract-new-nnnnn-cf1-1-sgl)|MSeg=Introduc-tion
|
|
25
|
-
|
|
26
|
-
# newpar
|
|
27
|
-
# newpar_block = p (8 s)
|
|
28
|
-
# sent_id = GUM_academic_exposure-2
|
|
29
|
-
# s_type = decl
|
|
30
|
-
# s_prominence = 3
|
|
31
|
-
# transition = null
|
|
32
|
-
# text = Research on adult-learned second language (L2) has provided considerable insight into the neurocognitive mechanisms underlying the learning and processing of L2 grammar [1]–[11].
|
|
33
|
-
1 Research research NOUN NN Number=Sing 12 nsubj 12:nsubj Discourse=context-background:2->14:2:sem-synym-4-8,108-109|Entity=(2-abstract-new-nnnns-cf2-1-coref
|
|
34
|
-
2 on on ADP IN _ 7 case 7:case _
|
|
35
|
-
3 adult adult NOUN NN Number=Sing 5 compound 5:compound Entity=(3-abstract-new-sssss-cf1-5-coref|SpaceAfter=No|XML=<w>
|
|
36
|
-
4 - - PUNCT HYPH _ 3 punct 3:punct SpaceAfter=No
|
|
37
|
-
5 learned learn VERB VBN Tense=Past|VerbForm=Part|Voice=Pass 7 amod 7:amod MSeg=learn-ed|XML=</w>
|
|
38
|
-
6 second second ADJ JJ Degree=Pos|NumForm=Word|NumType=Ord 7 amod 7:amod _
|
|
39
|
-
7 language language NOUN NN Number=Sing 1 nmod 1:nmod:on Entity=3)
|
|
40
|
-
8 ( ( PUNCT -LRB- _ 9 punct 9:punct Discourse=restatement-partial:3->2:0:sem-synym-4-8,10+grf-prn-9,11|SpaceAfter=No
|
|
41
|
-
9 L2 L2 NOUN NN Number=Sing 7 appos 7:appos Entity=(3-abstract-giv:act-sssss-cf1-1-appos)|SpaceAfter=No
|
|
42
|
-
10 ) ) PUNCT -RRB- _ 9 punct 9:punct Entity=2)
|
|
43
|
-
11 has have AUX VBZ Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin 12 aux 12:aux Discourse=same-unit_m:4->2:1:_|MSeg=ha-s
|
|
44
|
-
12 provided provide VERB VBN Tense=Past|VerbForm=Part 0 root 0:root MSeg=provid-ed
|
|
45
|
-
13 considerable considerable ADJ JJ Degree=Pos 14 amod 14:amod Entity=(4-abstract-new-nnnnn-cf4-2-sgl|MSeg=consider-able
|
|
46
|
-
14 insight insight NOUN NN Number=Sing 12 obj 12:obj MSeg=in-sigh-t
|
|
47
|
-
15 into into ADP IN _ 18 case 18:case MSeg=in-to
|
|
48
|
-
16 the the DET DT Definite=Def|PronType=Art 18 det 18:det Entity=(5-abstract-new-nnnnn-cf5-3-sgl
|
|
49
|
-
17 neurocognitive neurocognitive ADJ JJ Degree=Pos 18 amod 18:amod MSeg=neuro-cognit-ive
|
|
50
|
-
18 mechanisms mechanism NOUN NNS Number=Plur 14 nmod 14:nmod:into MSeg=mechan-ism-s
|
|
51
|
-
19 underlying underlie VERB VBG VerbForm=Ger 18 acl 18:acl Discourse=elaboration-attribute:5->4:0:syn-mdf-19+syn-nmn-20|MSeg=under-ly-ing
|
|
52
|
-
20 the the DET DT Definite=Def|PronType=Art 21 det 21:det Entity=(6-abstract-new-nnnnn-cf3-2,4-sgl
|
|
53
|
-
21 learning learning NOUN NN Number=Sing 19 obj 19:obj MSeg=learn-ing
|
|
54
|
-
22 and and CCONJ CC _ 23 cc 23:cc _
|
|
55
|
-
23 processing processing NOUN NN Number=Sing 21 conj 19:obj|21:conj:and MSeg=process-ing
|
|
56
|
-
24 of of ADP IN _ 26 case 26:case _
|
|
57
|
-
25 L2 L2 NOUN NN Number=Sing 26 compound 26:compound Entity=(7-abstract-new-nnnss-cf6-2-coref(3-abstract-giv:act-sssss-cf1-1-coref)
|
|
58
|
-
26 grammar grammar NOUN NN Number=Sing 21 nmod 21:nmod:of Entity=7)6)5)4)
|
|
59
|
-
27 [ [ PUNCT -LRB- _ 28 punct 28:punct Discourse=explanation-evidence:6->2:2:grf-prn-28,30,32,34|SpaceAfter=No|XML=<w>
|
|
60
|
-
28 1 1 NUM CD NumForm=Digit|NumType=Card 12 dep 12:dep Entity=(8-abstract-new-nnnnn-cf7-1-sgl)|SpaceAfter=No
|
|
61
|
-
29 ] ] PUNCT -RRB- _ 28 punct 28:punct SpaceAfter=No
|
|
62
|
-
30 – - SYM SYM _ 32 case 32:case SpaceAfter=No
|
|
63
|
-
31 [ [ PUNCT -LRB- _ 32 punct 32:punct SpaceAfter=No
|
|
64
|
-
32 11 11 NUM CD NumForm=Digit|NumType=Card 28 nmod 28:nmod:to Entity=(9-abstract-new-nnnnn-cf8-1-sgl)|SpaceAfter=No
|
|
65
|
-
33 ] ] PUNCT -RRB- _ 32 punct 32:punct SpaceAfter=No
|
|
66
|
-
34 . . PUNCT . _ 12 punct 12:punct XML=</w>
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "extends": "@nerd-bible/config/tsconfig.json" }
|