Skip to content
This repository was archived by the owner on Mar 20, 2022. It is now read-only.

Commit 443b079

Browse files
committed
Add type declarations
1 parent 81d95dd commit 443b079

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.0.1",
44
"description": "Normalizes JSON according to schema for Flux application",
55
"main": "lib/index.js",
6+
"typings": "typings.d.ts",
67
"repository": {
78
"type": "git",
89
"url": "https://github.com/gaearon/normalizr.git"

typings.d.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
export type SchemaOptions = {
2+
idAttribute?: string | Function;
3+
}
4+
5+
export type IterableSchemaOptions = {
6+
schemaAttribute?: string | Function;
7+
}
8+
9+
export type UnionSchemaOptions = {
10+
schemaAttribute: string | Function;
11+
}
12+
13+
export type NormalizeOptions = {
14+
assignEntity?: Function;
15+
mergeIntoEntity?: Function;
16+
}
17+
18+
export type NormalizeInput = Object | Array<Object>;
19+
20+
export type NormalizeOutput = {
21+
result: any;
22+
entities?: any;
23+
}
24+
25+
export class Schema {
26+
constructor (key: string, options?: SchemaOptions);
27+
28+
define(schema: SchemaMap): void;
29+
getKey(): string;
30+
getIdAttribute(): string;
31+
}
32+
33+
export class IterableSchema {
34+
constructor (schema: SchemaValue, options?: IterableSchemaOptions);
35+
36+
getItemSchema(): SchemaValue;
37+
}
38+
39+
export class UnionSchema {
40+
constructor (schema: SchemaValue, options: UnionSchemaOptions);
41+
42+
getItemSchema(): SchemaValue;
43+
}
44+
45+
export type SchemaValue = Schema | IterableSchema | UnionSchema | SchemaMap;
46+
47+
export type SchemaMap = {
48+
[key: string]: SchemaValue;
49+
}
50+
51+
export function arrayOf(
52+
schema: SchemaValue,
53+
options?: IterableSchemaOptions
54+
): IterableSchema;
55+
56+
export function valuesOf(
57+
schema: SchemaValue,
58+
options?: IterableSchemaOptions
59+
): IterableSchema;
60+
61+
export function unionOf(
62+
schema: SchemaValue,
63+
options?: UnionSchemaOptions
64+
): UnionSchema;
65+
66+
export function normalize(
67+
input: NormalizeInput,
68+
schema: SchemaValue,
69+
options?: NormalizeOptions
70+
): NormalizeOutput;

0 commit comments

Comments
 (0)