Skip to content

Commit

Permalink
Improved the filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
fenying committed Aug 4, 2018
1 parent 525bb68 commit 4486ece
Show file tree
Hide file tree
Showing 19 changed files with 1,969 additions and 715 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/dist/
/lib/
/node_modules/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"type": "node",
"request": "launch",
"name": "Do tests",
"program": "${workspaceFolder}/sources/tests.ts",
"name": "[TypeGuard] Do tests",
"program": "${workspaceFolder}/src/tests.ts",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/dist/*.js",
"${workspaceFolder}/dist/**/*.js"
"${workspaceFolder}/lib/*.js",
"${workspaceFolder}/lib/**/*.js"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "Build (Watching)",
"label": "[TypeGuard] Build (Watching)",
"command": "tsc",
"type": "shell",
"args": [
Expand Down
17 changes: 17 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changes Logs

## v0.3.0

- Upgrade TypeScript compiler to `v2.9.2`.
- Allowed built-in type in filter:

To ensure an unsigned integer less than 1000, the rule should be

```json
["$.and", "uint", "|value lt 1000"]
```

And now, use following rule instead:

```json
"|uint lt 1000"
```

## v0.2.0

- Added advanced type `$.struct` to exactly limit keys of object:
Expand Down
14 changes: 0 additions & 14 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,3 @@ enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same "printed page" as the copyright notice for easier identification within
third-party archives.

Copyright 2018 Angus.Fenying

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
27 changes: 14 additions & 13 deletions docs/zh-CN/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ const isBoolean = compiler.compile("boolean");

console.log(isUInt8(123));
console.log(isUInt8(255));
console.log(isUInt8(256)); // 超出 UInt8 的范围
console.log(isUInt8(256)); // 超出 UInt8 的范围
console.log(isBoolean(true));
console.log(isBoolean(null)); // null 不是 boolean 型
console.log(isBoolean(null)); // null 不是 boolean 型
console.log(isBoolean(false));
console.log(isBoolean(123)); // 123 不是 boolean 型
console.log(isBoolean(123)); // 123 不是 boolean 型
```

### 直接量

使用直接量表达式,可以校验数据是否为具体的值:

```js
compiler.compile(123); // 被校验的变量必须为数值 123(类型上完全匹配)
compiler.compile(null); // 被校验的变量必须为 null (类型上完全匹配)
compiler.compile(true); // 被校验的变量必须为布尔值 true (类型上完全匹配)
compiler.compile(false); // 被校验的变量必须为布尔值 false (类型上完全匹配)
compiler.compile(123); // 被校验的变量必须为数值 123(类型上完全匹配)
compiler.compile(null); // 被校验的变量必须为 null (类型上完全匹配)
compiler.compile(true); // 被校验的变量必须为布尔值 true (类型上完全匹配)
compiler.compile(false); // 被校验的变量必须为布尔值 false (类型上完全匹配)
```

### 字符串匹配
Expand Down Expand Up @@ -98,6 +98,7 @@ target 可以是如下值:
- `length` 变量的值长度(字符串长度或者数组长度)
- `string.length` 字符串变量的长度(会先校验是否为字符串)
- `array.length` 数组变量的长度(会先校验是否为数组)
- 任意简单类型

目前支持如下比较方式:

Expand Down Expand Up @@ -151,19 +152,19 @@ compiler.compile("|value ne 1");
compiler.compile("|value eq 1");

/**
* 被校验的值必须是奇数
* 被校验的值必须是整数且是奇数
*/
compiler.compile("|value odd");
compiler.compile("|uint odd");

/**
* 被校验的值必须是偶数
* 被校验的值必须是整数且是偶数
*/
compiler.compile("|value even");
compiler.compile("|uint even");

/**
* 被校验的值必须是 10 的倍数
* 被校验的值必须是整数且是 10 的倍数
*/
compiler.compile("|value timesof 10");
compiler.compile("|uint timesof 10");
```

## 高级类型
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

This file was deleted.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@litert/typeguard",
"version": "0.2.0",
"version": "0.3.0",
"description": "A type checking code \"JIT\" library.",
"main": "dist/index.js",
"main": "lib/index.js",
"scripts": {
"prepare": "npm run rebuild",
"build": "tsc -p .",
"rebuild": "npm run clean && npm run lint && npm run build",
"test": "echo See directory sources/samples",
"clean": "rm -rf dist",
"test": "node lib/tests.js",
"clean": "rm -rf lib",
"lint": "tslint -p . -c tslint.json"
},
"keywords": [
Expand All @@ -29,9 +29,11 @@
},
"homepage": "https://github.com/litert/type-guard#readme",
"dependencies": {},
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"devDependencies": {},
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"devDependencies": {
"typescript": "^2.9.2"
},
"engines": {
"node": ">=8.0.0"
}
Expand Down
47 changes: 0 additions & 47 deletions sources/compiler.javascript.ts

This file was deleted.

30 changes: 0 additions & 30 deletions sources/index.ts

This file was deleted.

Loading

0 comments on commit 4486ece

Please sign in to comment.