@produck/mold
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@produck/mold", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "For helping to create a final options from a defined specification.", | ||
@@ -46,3 +46,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "4faf23f9333cd3c5afc772933fccb1fb5f40d8e1" | ||
"gitHead": "3618c4d8dace902aecbfb01356a525d6db677591" | ||
} |
@@ -1,1 +0,5 @@ | ||
{} | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2015"] | ||
} | ||
} |
@@ -9,8 +9,19 @@ import { Schema } from './schema'; | ||
type MixinedObject< | ||
CustomSchemaList extends SchemaList | ||
> = ReturnType<CustomSchemaList[0]> | ||
| ReturnType<CustomSchemaList[1]> | ||
| ReturnType<CustomSchemaList[2]> | ||
| ReturnType<CustomSchemaList[3]> | ||
interface AndSchema { | ||
(andSchemaList: SchemaList): Schema; | ||
<CustomSchemaList extends SchemaList>( | ||
andSchemaList: CustomSchemaList | ||
): Schema<MixinedObject<CustomSchemaList>>; | ||
} | ||
interface OrSchema { | ||
(orSchemaList: SchemaList): Schema; | ||
<CustomSchemaList extends SchemaList>( | ||
orSchemaList: CustomSchemaList | ||
): Schema<MixinedObject<CustomSchemaList>>; | ||
} | ||
@@ -24,3 +35,6 @@ | ||
interface IfSchema { | ||
(test: Schema, options: IfOptions): Schema; | ||
<O extends IfOptions>( | ||
test: Schema, | ||
options: O | ||
): Schema<ReturnType<O["then"]> | ReturnType<O["else"]>>; | ||
} | ||
@@ -27,0 +41,0 @@ |
@@ -16,26 +16,46 @@ import { Schema } from './schema'; | ||
import * as Message from './Message'; | ||
export { Message }; | ||
export { Message, Message as Msg, Message as M }; | ||
type CircularProxy = (reference: Schema) => void; | ||
type CircularProxy< | ||
CustomSchema extends Schema | ||
> = ( | ||
self: CustomSchema | ||
) => CustomSchema | ||
interface CircularSchema { | ||
(proxy: CircularProxy): Schema; | ||
< | ||
CustomCircularProxy extends CircularProxy<Schema> | ||
>( | ||
proxy: CustomCircularProxy | ||
): ReturnType<CustomCircularProxy>; | ||
} | ||
type CustomProxy = (_value: any, _empty: boolean, next: () => any) => any; | ||
interface CustomSchema { | ||
(schema: Schema, proxy?: CustomProxy): Schema; | ||
<CustomSchema extends Schema>( | ||
schema: CustomSchema, | ||
proxy?: ( | ||
_value: ReturnType<CustomSchema>, | ||
_empty: boolean, | ||
next: () => ReturnType<CustomSchema> | ||
) => any | ||
): CustomSchema; | ||
} | ||
interface normalize { | ||
(_value: any): any; | ||
interface Normalizer<Type> { | ||
(_value: Type): Type; | ||
} | ||
interface Normalizer { | ||
(schema: Schema, caught?: Function): normalize; | ||
interface NormalizerConstructor { | ||
<CustomSchema extends Schema>( | ||
schema: CustomSchema, | ||
caught?: Function | ||
): Normalizer<ReturnType<CustomSchema>>; | ||
} | ||
export const Circular: CircularSchema; | ||
export const Circ: CircularSchema; | ||
export const Custom: CustomSchema; | ||
export const Normalizer: Normalizer; | ||
export const Cust: CustomSchema; | ||
export const Normalizer: NormalizerConstructor; |
@@ -1,1 +0,4 @@ | ||
export const Origin: () => {}; | ||
export const Origin: () => {}; | ||
export const Plain: () => {}; | ||
export const Full: () => {}; | ||
export const Visual: () => {}; |
import { Schema } from './schema'; | ||
export const Constant: (value: any) => Schema; | ||
export const Constant: <Type>(value: Type) => Schema<Type>; | ||
export const Enum: (valueList: Array<any>) => Schema; | ||
export const Null: Schema; | ||
export const NotNull: Schema; | ||
export const OrNull: (schema: Schema) => Schema; | ||
export const Number: (defaultValue: number) => Schema; | ||
export const String: (defaultValue: string) => Schema; | ||
export const Boolean: (defaultValue: boolean) => Schema; | ||
export const Function: (defaultValue: Function) => Schema; | ||
export const Symbol: (defaultValue: symbol) => Schema; | ||
export const Integer: (defaultValue: number) => Schema; | ||
export const Null: Schema<null>; | ||
export const NotNull: Schema<Exclude<any, null>>; | ||
export const OrNull: < | ||
CustomSchema extends Schema = Schema | ||
>( | ||
schema: CustomSchema | ||
) => CustomSchema | Schema<null>; | ||
export const Instance: < | ||
CustomConstructor extends abstract new (...args) => any | ||
>( | ||
/** | ||
* Anything can be used as a constructor | ||
*/ | ||
Constructor: CustomConstructor | ||
) => Schema<InstanceType<CustomConstructor>> | ||
type NativeSchema<Type = any> = ( | ||
/** | ||
* No default value means required. | ||
*/ | ||
defaultValue?: Type | ||
) => Schema<Type> | ||
type NumberNativeSchema = NativeSchema<number>; | ||
export const Number: NumberNativeSchema; | ||
export const NumberRange: ( | ||
edge?: [minValue?: number, maxValue?: number], | ||
open?: [minOpen?: boolean, maxOpen?: boolean], | ||
) => NumberNativeSchema; | ||
export const Integer: NumberNativeSchema; | ||
export const IntegerMultipleOf: (base: number) => NumberNativeSchema; | ||
export const Port: NumberNativeSchema; | ||
export const INT8: NumberNativeSchema; | ||
export const UINT8: NumberNativeSchema; | ||
export const INT16: NumberNativeSchema; | ||
export const UINT16: NumberNativeSchema; | ||
export const INT24: NumberNativeSchema; | ||
export const UINT24: NumberNativeSchema; | ||
export const INT32: NumberNativeSchema; | ||
export const UINT32: NumberNativeSchema; | ||
export const Byte: NumberNativeSchema; | ||
export const String: NativeSchema<string>; | ||
export const StringPattern: (pattern: RegExp, name?: string) => NativeSchema<string>; | ||
export const StringLength: (min: number, max?: number) => NativeSchema<string>; | ||
export const Boolean: NativeSchema<boolean>; | ||
export const Function: NativeSchema<Function>; | ||
export const Symbol: NativeSchema<symbol>; |
@@ -1,3 +0,3 @@ | ||
export interface Schema { | ||
(_value: any, _empty: boolean): any; | ||
export interface Schema<ValueType = any> { | ||
(_value: any, _empty: boolean): ValueType; | ||
} |
@@ -6,24 +6,62 @@ import { Schema } from './schema'; | ||
interface ArraySchema { | ||
(itemSchema: Schema): Schema; | ||
(itemSchema: Schema, expected: string): Schema; | ||
(itemSchema: Schema, DefaultValue: DefaultValue): Schema; | ||
(itemSchema: Schema, expected: string, DefaultValue: DefaultValue): Schema; | ||
<CustomSchema extends Schema = Schema<any>>( | ||
itemSchema: CustomSchema, | ||
expected?: string, | ||
DefaultValue?: DefaultValue | ||
): Schema<Array<ReturnType<CustomSchema>>>; | ||
<CustomSchema extends Schema = Schema<any>>( | ||
itemSchema: CustomSchema, | ||
DefaultValue: DefaultValue | ||
): Schema<Array<ReturnType<CustomSchema>>>; | ||
} | ||
type SchemaList = Array<Schema>; | ||
type SchemaTuple<S extends Schema = Schema> = [] | ||
| [S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S, S, S, S, S] | [S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S] | ||
| [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S]; | ||
type CombinedTuple< | ||
CustomSchemaTuple extends SchemaTuple | ||
> = { | ||
[Index in keyof CustomSchemaTuple]: ReturnType<CustomSchemaTuple[Index]> | ||
}; | ||
interface TupleSchema { | ||
(schemaList: SchemaList): Schema; | ||
(schemaList: SchemaList, expected: string): Schema; | ||
(schemaList: SchemaList, DefaultValue: DefaultValue): Schema; | ||
(schemaList: SchemaList, expected: string, DefaultValue: DefaultValue): Schema; | ||
<CustomSchemaTuple extends SchemaTuple>( | ||
schemaList: CustomSchemaTuple, | ||
expected?: string, | ||
DefaultValue?: DefaultValue | ||
): Schema<CombinedTuple<CustomSchemaTuple>>; | ||
<CustomSchemaTuple extends SchemaTuple>( | ||
schemaList: CustomSchemaTuple, | ||
DefaultValue: DefaultValue | ||
): Schema<CombinedTuple<CustomSchemaTuple>>; | ||
} | ||
type Validate = (any: any) => boolean; | ||
type Validate<Type = any> = (any: Type) => boolean; | ||
interface ValueSchema { | ||
(validate: Validate): Schema; | ||
(validate: Validate, expected: string): Schema; | ||
(validate: Validate, DefaultValue: DefaultValue): Schema; | ||
(validate: Validate, expected: string, DefaultValue: DefaultValue): Schema; | ||
<CustomValidate extends Validate>( | ||
validate: CustomValidate, | ||
expected?: string, | ||
DefaultValue?: DefaultValue | ||
): CustomValidate extends Validate<infer V> ? Schema<V> : never; | ||
<CustomValidate extends Validate>( | ||
validate: CustomValidate, | ||
DefaultValue: DefaultValue | ||
): CustomValidate extends Validate<infer V> ? Schema<V>: never; | ||
} | ||
@@ -35,7 +73,19 @@ | ||
type CombinedObject< | ||
CustomSchemaMap extends SchemaMap | ||
> = { | ||
[Property in keyof CustomSchemaMap]: ReturnType<CustomSchemaMap[Property]> | ||
} | ||
interface ObjectSchema { | ||
(schemaMap: SchemaMap): Schema; | ||
(schemaMap: SchemaMap, expected: string): Schema; | ||
(schemaMap: SchemaMap, DefaultValue: DefaultValue): Schema; | ||
(schemaMap: SchemaMap, expected: string, DefaultValue: DefaultValue): Schema; | ||
<CustomSchemaMap extends SchemaMap = {}>( | ||
schemaMap?: CustomSchemaMap, | ||
expected?: string, | ||
DefaultValue?: DefaultValue | ||
): Schema<CombinedObject<CustomSchemaMap>>; | ||
<CustomSchemaMap extends SchemaMap>( | ||
schemaMap: CustomSchemaMap, | ||
DefaultValue: DefaultValue | ||
): Schema<CombinedObject<CustomSchemaMap>>; | ||
} | ||
@@ -42,0 +92,0 @@ |
@@ -1,36 +0,36 @@ | ||
type Validate = (any: any) => boolean; | ||
type Validate<Type = any> = (any: Type) => boolean; | ||
export namespace Native { | ||
const Undefined: Validate; | ||
const Number: Validate; | ||
const String: Validate; | ||
const Boolean: Validate; | ||
const Function: Validate; | ||
const Object: Validate; | ||
const Symbol: Validate; | ||
const BigInt: Validate; | ||
const Undefined: Validate<undefined>; | ||
const Number: Validate<number>; | ||
const String: Validate<string>; | ||
const Boolean: Validate<boolean>; | ||
const Function: Validate<Function>; | ||
const Object: Validate<object>; | ||
const Symbol: Validate<symbol>; | ||
const BigInt: Validate<bigint>; | ||
} | ||
export namespace Helper { | ||
const Null: Validate; | ||
const Array: Validate; | ||
const PlainObjectLike: Validate; | ||
const Null: Validate<null>; | ||
const Array: Validate<Array<any>>; | ||
const PlainObjectLike: Validate<object>; | ||
} | ||
export namespace Number { | ||
const Integer: Validate; | ||
const Infinity: Validate; | ||
const NaN: Validate; | ||
const Integer: Validate<number>; | ||
const Infinity: Validate<number>; | ||
const NaN: Validate<number>; | ||
} | ||
export namespace Object { | ||
const RegExp: Validate; | ||
const Date: Validate; | ||
const Array: Validate; | ||
const Error: Validate; | ||
const Map: Validate; | ||
const Set: Validate; | ||
const WeakMap: Validate; | ||
const WeakSet: Validate; | ||
const Promise: Validate; | ||
const RegExp: Validate<RegExp>; | ||
const Date: Validate<Date>; | ||
const Array: Validate<Array<any>>; | ||
const Error: Validate<Error>; | ||
const Map: Validate<Map<any, any>>; | ||
const Set: Validate<Set<any>>; | ||
const WeakMap: Validate<WeakMap<any, any>>; | ||
const WeakSet: Validate<WeakSet<any>>; | ||
const Promise: Validate<Promise<any>>; | ||
} |
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
47439
1384
38