Skip to content

Commit

Permalink
Merge pull request #459 from shimataro/develop
Browse files Browse the repository at this point in the history
version 3.0.0-rc.4
  • Loading branch information
shimataro committed May 16, 2020
2 parents a925769 + 9ccb700 commit 2fe9ede
Show file tree
Hide file tree
Showing 9 changed files with 3,592 additions and 1,444 deletions.
43 changes: 42 additions & 1 deletion .github/workflows/verify-examples.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# https://help.github.com/en/articles/workflow-syntax-for-github-actions

on: push
name: Examples
on: push

jobs:
cjs:
name: CommonJS
Expand Down Expand Up @@ -58,6 +59,7 @@ jobs:
run: node ./examples/example.js
- name: Run example (TypeScript/Babel compatible)
run: node ./examples/example-default.js

esm:
name: ES Modules
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -117,6 +119,7 @@ jobs:
run: node --experimental-modules ./examples/example-default.js
- name: Run example (ESM)
run: node --experimental-modules ./examples/example.mjs

conditional-exports:
name: Conditional Exports
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -166,3 +169,41 @@ jobs:
run: node --experimental-conditional-exports ./examples/example-default.js
- name: Run example (ESM)
run: node --experimental-conditional-exports ./examples/example.mjs

deno:
name: Deno
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- windows-latest
- macos-latest
- ubuntu-latest
deno:
- "1.0.0"
fail-fast: false
steps:
- name: Checkout source codes
uses: actions/checkout@v2
- name: Install Node.js v12
uses: actions/setup-node@v1
with:
node-version: 12
- name: Output versions
run: |
node -v
npm -v
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Install dependencies (only production)
run: npm ci --only=production
- name: Install Deno
uses: denolib/setup-deno@v1.3.0
with:
deno-version: ${{ matrix.deno }}
- name: Check syntax
run: deno run ./mod.ts
- name: Run example
run: deno run ./examples/example-deno.ts
2 changes: 1 addition & 1 deletion .markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ MD024: # no-duplicate-heading
MD029: # ol-prefix
style: one
MD035: # hr-style
style: "---"
style: "==="
MD048: # code-fence-style
style: backtick
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.0.0-rc.4] - 2020-05-16

### Added

* supports [Deno](https://deno.land/)

## [3.0.0-rc.3] - 2020-02-28

### Added
Expand Down Expand Up @@ -453,7 +459,8 @@ 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.3...HEAD
[Unreleased]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.4...HEAD
[3.0.0-rc.4]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.3...v3.0.0-rc.4
[3.0.0-rc.3]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.2...v3.0.0-rc.3
[3.0.0-rc.2]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.1...v3.0.0-rc.2
[3.0.0-rc.1]: https://github.com/shimataro/value-schema/compare/v2.2.6...v3.0.0-rc.1
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

simple, easy-to-use, and declarative schema validator

supports [Node.js](https://nodejs.org/) and [Deno](https://deno.land/)

## Table of Contents

* [Introduction](#introduction)
Expand All @@ -29,7 +31,7 @@ simple, easy-to-use, and declarative schema validator
* [object](#object)
* [Changelog](#changelog)

---
===

## Introduction

Expand Down Expand Up @@ -191,6 +193,14 @@ $ node --experimental-modules foo.mjs

**TypeScript** auto-completion and type-checking works perfectly on [Visual Studio Code](https://code.visualstudio.com/) and [IntelliJ IDEA](https://www.jetbrains.com/idea/)!

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

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

```typescript
import vs from "https://deno.land/x/value-schema/mod.ts";
```

## Reference

### types and constants
Expand Down
101 changes: 101 additions & 0 deletions examples/example-deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import * as assert from "https://deno.land/std/testing/asserts.ts";
import vs from "../mod.ts";

const schemaObject: vs.SchemaObject = { // schema for input
id: vs.number({ // number, >=1
minValue: 1,
}),
name: vs.string({ // string, max 16 characters (trims if over)
maxLength: {
length: 16,
trims: true,
},
}),
age: vs.number({ // number, integer (trims if decimal), >=0
integer: vs.NUMBER.INTEGER.FLOOR_RZ,
minValue: 0,
}),
email: vs.email(), // email
state: vs.string({ // string, accepts only "active" and "inactive"
only: ["active", "inactive"],
}),
classes: vs.array({ // array of number, separated by ",", ignores errors
separatedBy: ",",
each: {
schema: vs.number(),
ignoresErrors: true,
},
}),
skills: vs.array({ // array of string, separated by ",", ignores errors
separatedBy: ",",
each: {
schema: vs.string(),
ignoresErrors: true,
},
}),
creditCard: vs.numericString({ // numeric string, separated by "-", checks by Luhn algorithm
separatedBy: "-",
checksum: vs.NUMERIC_STRING.CHECKSUM_ALGORITHM.CREDIT_CARD,
}),
remoteAddr: vs.string({ // IPv4
pattern: vs.STRING.PATTERN.IPV4,
}),
remoteAddrIpv6: vs.string({ // IPv6
pattern: vs.STRING.PATTERN.IPV6,
}),
limit: vs.number({ // number, integer, omittable (sets 10 if omitted), >=1 (sets 1 if less), <=100 (sets 100 if greater)
ifUndefined: 10,
integer: true,
minValue: {
value: 1,
adjusts: true,
},
maxValue: {
value: 100,
adjusts: true,
},
}),
offset: vs.number({ // number, integer, omittable (sets 0 if omitted), >=0 (sets 0 if less)
ifUndefined: 0,
integer: true,
minValue: {
value: 0,
adjusts: true,
},
}),
};
const input = { // input values
id: "1",
name: "Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Ciprin Cipriano de la Santísima Trinidad Ruiz y Picasso",
age: 20.5,
email: "picasso@example.com",
state: "active",
classes: "1,3,abc,4",
skills: "c,c++,javascript,python,,swift,kotlin",
creditCard: "4111-1111-1111-1111",
remoteAddr: "127.0.0.1",
remoteAddrIpv6: "::1",
limit: "0",
};
const expected = { // should be converted to this
id: 1,
name: "Pablo Diego José",
age: 20,
email: "picasso@example.com",
state: "active",
classes: [1, 3, 4],
skills: ["c", "c++", "javascript", "python", "swift", "kotlin"],
creditCard: "4111111111111111",
remoteAddr: "127.0.0.1",
remoteAddrIpv6: "::1",
limit: 1,
offset: 0,
};

// Let's apply!
const actual = vs.applySchemaObject(schemaObject, input);

// verification
assert.assertEquals(actual, expected);

console.log("Deno: OK!🎉");
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from "./dist/index.ts";

0 comments on commit 2fe9ede

Please sign in to comment.