@produck/mold
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "@produck/mold", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "For helping to create a final options from a defined specification.", | ||
@@ -46,3 +46,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "3618c4d8dace902aecbfb01356a525d6db677591" | ||
"gitHead": "48c1b4d07ee3a663c57202ecd4a52429042bc430" | ||
} |
@@ -7,6 +7,58 @@ # `mold` | ||
``` | ||
const mold = require('mold'); | ||
```js | ||
import { S, C, P, Normalizer, Circular } from '@produck/mold'; | ||
/** | ||
* S = Simplex { Object, Array, Tuple, Value } | ||
* C = Compound { Not, And, Or, If } | ||
* P = Preset { Constant, Enum, Null, NotNull, Instance, Number, String, ... } | ||
*/ | ||
// TODO: DEMONSTRATE API | ||
const Object = S.Object({ | ||
c: P.Constant(1), | ||
a: S.Object({ | ||
b: P.String('foo'), | ||
c: P.Boolean(true) | ||
}), | ||
l: S.Array(S.Object({ | ||
s: P.String('') | ||
})), | ||
d: S.Object({}), | ||
e: P.OrNull(P.Symbol()), | ||
route: Circular(schema => S.Object({ | ||
name: P.String(), | ||
next: schema, | ||
previous: schema | ||
})), | ||
D: P.Instance(Date), | ||
point: S.Tuple([P.Number(0), P.Number(0), P.String('baz')]), | ||
port: P.Port(80), | ||
p: P.StringPattern(/[a-f0-9]+/)('9f'), | ||
l: P.StringLength(5)('33333'), | ||
m5: P.IntegerMultipleOf(5)(10) | ||
}); | ||
const normalize = Normalizer(Object); | ||
try { | ||
const finalOptions = normalize({ | ||
c: 1, | ||
route: { | ||
name: 'a', | ||
next: { | ||
name: 'b', | ||
previous: null, | ||
next: { | ||
} | ||
}, | ||
previous: null | ||
}, | ||
e: null, | ||
D: new Date(), | ||
point: [0], | ||
}); | ||
console.log(finalOptions); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
@@ -13,0 +65,0 @@ |
@@ -15,4 +15,6 @@ import { Schema } from './schema'; | ||
import * as Message from './Message'; | ||
export { Message, Message as Msg, Message as M }; | ||
export namespace Catcher { | ||
const Origin: () => {}; | ||
const Simple: () => {}; | ||
} | ||
@@ -19,0 +21,0 @@ type CircularProxy< |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
50750
1474
84
37