Skip to content

Commit

Permalink
Merge branch 'develop' into feature/union
Browse files Browse the repository at this point in the history
  • Loading branch information
shimataro committed Apr 1, 2021
2 parents 85894ca + 1fbac90 commit 3978970
Show file tree
Hide file tree
Showing 107 changed files with 2,230 additions and 2,032 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/verify-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ jobs:
- name: Check syntax
run: node ./dist/index.js
- name: Install dependencies (example)
run: npm --prefix ./examples i --only=production
run: npm i --only=production
working-directory: ./examples
- name: Run example
run: node ./examples/example.js
- name: Run example (TypeScript/Babel compatible)
Expand Down Expand Up @@ -114,7 +115,8 @@ jobs:
- name: Check syntax (ESM)
run: node --experimental-modules ./dist/index.mjs
- name: Install dependencies (example)
run: npm --prefix ./examples i --only=production
run: npm i --only=production
working-directory: ./examples
- name: Run example (CJS)
run: node --experimental-modules ./examples/example.js
- name: Run example (CJS; TypeScript/Babel compatible)
Expand Down Expand Up @@ -166,7 +168,8 @@ jobs:
- name: Check syntax (ESM)
run: node --experimental-conditional-exports ./dist/index.mjs
- name: Install dependencies (example)
run: npm --prefix ./examples i --only=production
run: npm i --only=production
working-directory: ./examples
- name: Run example (CJS)
run: node --experimental-conditional-exports ./examples/example.js
- name: Run example (CJS; TypeScript/Babel compatible)
Expand All @@ -190,14 +193,21 @@ jobs:
- "1.1.0"
- "1.2.0"
- "1.3.0"
- "1.4.0"
- "1.5.0"
- "1.6.0"
- "1.7.0"
- "1.8.0"
fail-fast: false
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install Deno
uses: denolib/setup-deno@v1.3.0
uses: denolib/setup-deno@v2
with:
deno-version: ${{ matrix.deno }}
- name: Output versions
run: deno --version
- name: Check syntax
run: deno run ./mod.ts
- name: Run example
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify-on-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- "3.8"
- "3.9"
- "4.0"
- "4.1"
- "4.2"
fail-fast: false
steps:
- name: Checkout source codes
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify-on-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- "3.8"
- "3.9"
- "4.0"
- "4.1"
- "4.2"
fail-fast: false
steps:
- name: Checkout source codes
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify-on-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- "3.8"
- "3.9"
- "4.0"
- "4.1"
- "4.2"
fail-fast: false
steps:
- name: Turn off auto-crlf
Expand Down
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,29 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* `union()`

### Fixed

* TypeScript example in README

### Others

* add JSDoc comments for parameters
* support TypeScript 4.2
* support Deno 1.7, 1.8

## [3.0.0] - 2020-12-09

### Others

* support TypeScript 4.1
* support Deno 1.6

## [3.0.0-rc.15] - 2020-11-08

### Others

* support TypeScript 4.0
* support Deno 1.3
* support Deno 1.3, 1.4, 1.5

## [3.0.0-rc.14] - 2020-07-26

Expand Down Expand Up @@ -539,7 +558,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* First release.

[Unreleased]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.14...HEAD
[Unreleased]: https://github.com/shimataro/value-schema/compare/v3.0.0...HEAD
[3.0.0]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.15...v3.0.0
[3.0.0-rc.15]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.14...v3.0.0-rc.15
[3.0.0-rc.14]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.13...v3.0.0-rc.14
[3.0.0-rc.13]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.12...v3.0.0-rc.13
[3.0.0-rc.12]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.11...v3.0.0-rc.12
Expand Down
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ $ node --experimental-modules foo.mjs

### [Deno](https://deno.land/)

Deno has been supported as of v3.0.0-rc.4.
Deno has been supported as of v3.

```typescript
import vs from "https://deno.land/x/value_schema/mod.ts";
import vs from "https://deno.land/x/value_schema/mod.ts"; // latest version
import vs from "https://deno.land/x/value_schema@3/mod.ts"; // latest version of v3
import vs from "https://deno.land/x/value_schema@3.0.0/mod.ts"; // v3.0.0
```

**CAUTION**: specify `value_schema` (underscore) NOT `value-schema` (hyphen) because [deno.land](https://deno.land/) module database does not support name with hyphen!
Expand Down Expand Up @@ -468,25 +470,7 @@ const actual = vs.applySchemaObject(schemaObject, input);
assert.deepStrictEqual(actual, expected);
```

In TypeScript, use "Generics" for type-safe.

```typescript
interface Parameters {
foo: number
bar: string
}

const schemaObject = {
foo: vs.number(),
bar: vs.string(),
};
const input = {
foo: "12345",
bar: "abcde",
};

const actual = vs.applySchemaObject<Parameters>(schemaObject, input);
```
In TypeScript, type inference and auto-completion work perfectly!

###### error handling 1

Expand Down
3 changes: 3 additions & 0 deletions dist-deno/appliers/array/each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { Key, Values, isArray } from "../../libs/types.ts";
import { ValueSchemaError } from "../../libs/ValueSchemaError.ts";
import { BaseSchema } from "../../schemaClasses/BaseSchema.ts";
type Each<T> = {
/** specifies schema of each elements */
schema: BaseSchema<T>;
/** ignores even if some elements cause error */
ignoresErrors: boolean;
};
type EachLike<T> = BaseSchema<T> | Each<T>;
export interface Options<T> {
/** specifies schema of each elements */
each?: EachLike<T>;
}
/**
Expand Down
3 changes: 3 additions & 0 deletions dist-deno/appliers/array/maxLength.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Key, Values, isArray, isNumber } from "../../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
type MaxLength = {
/** maximum size of array */
length: number;
/** removes trailing elements if too long */
trims: boolean;
};
type MaxLengthLike = number | MaxLength;
export interface Options {
/** maximum size of array */
maxLength?: MaxLengthLike;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/array/minLength.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, Values, isArray } from "../../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
export interface Options {
/** minimum size of array */
minLength?: number;
}
/**
Expand Down
2 changes: 2 additions & 0 deletions dist-deno/appliers/array/type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Key, Values, isArray, isString } from "../../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
export interface Options {
/** assumes entire values are in one string separated by pattern */
separatedBy?: string | RegExp;
/** makes array that has 1 element if input value is not an array */
toArray?: boolean;
}
/**
Expand Down
2 changes: 2 additions & 0 deletions dist-deno/appliers/boolean/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
const REGEXP_TRUE = /^\s*(true|yes|on)\s*$/i;
const REGEXP_FALSE = /^\s*(false|no|off)\s*$/i;
export interface Options {
/** does not convert type; causes error if type does not match */
strictType?: boolean;
/** accepts all number value not only 0 and 1 (0 means false, others true) */
acceptsAllNumbers?: boolean;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/converter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, Values } from "../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../libs/ValueSchemaError.ts";
export interface Options<T> {
/** converter function */
converter?: (value: T, fail: () => never) => T;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/email/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { REGEXP_EMAIL } from "../../libs/regexp/email.ts";
import { Key, Values } from "../../libs/types.ts";
import * as pattern from "../string/pattern.ts";
export interface Options {
/** overwrites email pattern */
pattern?: RegExp;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/ifEmptyString.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, Values } from "../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../libs/ValueSchemaError.ts";
export interface Options<T> {
/** value if empty string (defaults: error) */
ifEmptyString?: T | null;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/ifNull.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, Values } from "../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../libs/ValueSchemaError.ts";
export interface Options<T> {
/** value if null (defaults: error) */
ifNull?: T | null;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/ifUndefined.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, Values } from "../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../libs/ValueSchemaError.ts";
export interface Options<T> {
/** value if undefined (defaults: error) */
ifUndefined?: T | null;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/number/acceptsFullWidth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as string from "../../libs/string.ts";
import { Key, Values, isString } from "../../libs/types.ts";
export interface Options {
/** accepts full width string; e.g., "12345" */
acceptsFullWidth?: boolean;
}
/**
Expand Down
3 changes: 3 additions & 0 deletions dist-deno/appliers/number/maxValue.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Key, Values, isNumber } from "../../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
type MaxValue = {
/** maximum value */
value: number;
/** true to adjust if input is greater than "value" / false to error */
adjusts: boolean;
};
type MaxValueLike = number | MaxValue;
export interface Options {
/** maximum value (value or object) */
maxValue?: MaxValueLike;
}
/**
Expand Down
3 changes: 3 additions & 0 deletions dist-deno/appliers/number/minValue.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Key, Values, isNumber } from "../../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
type MinValue = {
/** minimum value */
value: number;
/** true to adjust if input is less than "value" / false to error */
adjusts: boolean;
};
type MinValueLike = number | MinValue;
export interface Options {
/** minimum value (value or object) */
minValue?: MinValueLike;
}
/**
Expand Down
13 changes: 13 additions & 0 deletions dist-deno/appliers/number/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@ import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
const REGEXP_NUMBER = /^\s*[+-]?(\d+(\.\d*)?|\.\d+)\s*$/;
const REGEXP_INTEGER = /^\s*[+-]?\d+\s*$/;
export enum INTEGER {
/** does not care */
NO,
/** must be integer; causes error if otherwise */
YES,
/** rounds down (towards minus infinity) */
FLOOR,
/** rounds towards 0 (away from infinity) */
FLOOR_RZ,
/** rounds up (towards plus infinity) */
CEIL,
/** rounds away from 0 (towards infinity) */
CEIL_RI,
/** rounds half up (towards positive infinity) */
HALF_UP,
/** rounds half towards zero (away from infinity) */
HALF_UP_RZ,
/** rounds half down (towards negative infinity) */
HALF_DOWN,
/** rounds half away from zero (towards infinity) */
HALF_DOWN_RZ
}
type IntegerLike = boolean | INTEGER;
export interface Options {
/** does not convert type; causes error if type does not match */
strictType?: boolean;
/** accepts string with special format; e.g., "1e+2", "0x100" */
acceptsSpecialFormats?: boolean;
/** needs integer */
integer?: IntegerLike;
}
/**
Expand Down
7 changes: 7 additions & 0 deletions dist-deno/appliers/numericString/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { Key, Values, isString } from "../../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../../libs/ValueSchemaError.ts";
export enum CHECKSUM_ALGORITHM {
/** Luhn algorithm; used in credit card and IMEI (also known as MOD-10 algorithm) */
LUHN = "luhn",
/** checksum as credit card; equivalent to LUHN */
CREDIT_CARD = LUHN,
/** modulus10/weight3:1 algorithm; used in ISBN13, EAN and JAN */
MODULUS10_WEIGHT3_1 = "modulus10/weight3:1",
/** ISBN-13; equivalent to MODULUS10_WEIGHT3_1 */
ISBN13 = MODULUS10_WEIGHT3_1,
/** EAN code; equivalent to MODULUS10_WEIGHT3_1 */
EAN = MODULUS10_WEIGHT3_1,
/** JAN code; equivalent to MODULUS10_WEIGHT3_1 */
JAN = MODULUS10_WEIGHT3_1
}
export interface Options {
/** uses checksum */
checksum?: CHECKSUM_ALGORITHM;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/numericString/fullWidthToHalf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as string from "../../libs/string.ts";
import { Key, Values, isString } from "../../libs/types.ts";
export interface Options {
/** converts full width digit to half width */
fullWidthToHalf?: boolean;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/numericString/joinsArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Key, Values, isArray } from "../../libs/types.ts";
export interface Options {
/** joins array and makes string */
joinsArray?: boolean;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/numericString/separatedBy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Key, Values, isString } from "../../libs/types.ts";
export interface Options {
/** assumes input value is separated by pattern and ignores it */
separatedBy?: string | RegExp;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/object/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Key, ObjectTypeOf, SchemaObject, Values } from "../../libs/types.ts";
import { applySchemaObjectCore } from "../../libs/applySchemaObjectCore.ts";
import { onErrorDefault, onFinishedDefault } from "../../schemaClasses/BaseSchema.ts";
export interface Options<S> {
/** schema object */
schemaObject?: S;
}
/**
Expand Down
1 change: 1 addition & 0 deletions dist-deno/appliers/only.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, Values } from "../libs/types.ts";
import { CAUSE, ValueSchemaError } from "../libs/ValueSchemaError.ts";
export interface Options<T> {
/** accepts only specified values */
only?: T[];
}
/**
Expand Down

0 comments on commit 3978970

Please sign in to comment.