-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02ed00c
Showing
16 changed files
with
4,634 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"extends": "@hazmi35/eslint-config/typescript", | ||
"rules": { | ||
"sort-keys": 0, | ||
"@typescript-eslint/no-non-null-asserted-optional-chain": 0, | ||
"@typescript-eslint/explicit-function-return-type": 0, | ||
"@typescript-eslint/explicit-member-accessibility": 0, | ||
"@typescript-eslint/no-unnecessary-condition": 0, | ||
"@typescript-eslint/ban-ts-comment": 0, | ||
"@typescript-eslint/no-extraneous-class": 0, | ||
"@typescript-eslint/member-ordering": 0, | ||
"@typescript-eslint/restrict-template-expressions": 0, | ||
"no-eq-null": 0, | ||
"no-negated-condition": 0, | ||
"@typescript-eslint/prefer-optional-chain": 0, | ||
"@typescript-eslint/no-unsafe-argument": 0, | ||
"@typescript-eslint/naming-convention": 0, | ||
"function-call-argument-newline": 0, | ||
"@typescript-eslint/no-base-to-string": 0, | ||
"@typescript-eslint/member-delimiter-style": 0, | ||
"@typescript-eslint/semi": 0, | ||
"@typescript-eslint/no-extra-parens": 0, | ||
"@typescript-eslint/sort-type-union-intersection-members": 0, | ||
"class-methods-use-this": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm i yaml@next | ||
- run: npm i | ||
- run: npm run build | ||
- run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.vscode | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Chamaelyn Azusfin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
# yaml-schema | ||
> YAML document schema validator and transformer | ||
[![NPM Version](https://img.shields.io/npm/v/yaml-schema.svg?maxAge=3600)](https://www.npmjs.com/package/yaml-schema) | ||
[![NPM Downloads](https://img.shields.io/npm/dt/yaml-schema.svg?maxAge=3600)](https://www.npmjs.com/package/yaml-schema) | ||
|
||
## Example | ||
```js | ||
import { readFileSync } from "node:fs" | ||
import { YAML } from "yaml-schema" | ||
|
||
const configFile = readFIleSync("config.yml", "utf-8") | ||
|
||
const yaml = new YAML({ | ||
type: "object", | ||
props: { | ||
id: { | ||
type: "string" | ||
}, | ||
token: { | ||
type: "string | ||
} | ||
} | ||
}) | ||
const config = yaml.parse(configFile) | ||
``` | ||
## How To Use | ||
```js | ||
import { YAML } from "yaml-schema" | ||
const yaml = new YAML(schema) | ||
yaml.parse(yamlString) | ||
``` | ||
## Schema | ||
```js | ||
const yaml = new YAML({ | ||
type: schemaType | ||
default?: defaultValue | ||
}) | ||
``` | ||
Example: | ||
```js | ||
const yaml = new YAML({ | ||
type: "object", | ||
props: { | ||
name: { | ||
type: "string" | ||
} | ||
} | ||
}) | ||
``` | ||
Types: | ||
- any | ||
- boolean | ||
- number | ||
- string | ||
- choices | ||
- array | ||
- object | ||
### Schema Additional Properties | ||
`number` schema: | ||
```js | ||
const yaml = new YAML({ | ||
type: "number", | ||
limit?: { | ||
min?: number, | ||
max?: number | ||
} | ||
}) | ||
``` | ||
`string` schema: | ||
```js | ||
const yaml = new YAML({ | ||
type: "string", | ||
length?: { | ||
min?: number, | ||
max?: number | ||
} | ||
}) | ||
``` | ||
`choices` schema: | ||
choices allow numbers and strings | ||
```js | ||
const yaml = new YAML({ | ||
type: "choices", | ||
choices: [ | ||
"first choice", | ||
"second choice", | ||
"third choice" | ||
] | ||
}) | ||
``` | ||
`array` schema: | ||
```js | ||
const yaml = new YAML({ | ||
type: "array", | ||
element: anotherSchema, | ||
length?: { | ||
min?: number, | ||
max?: number | ||
} | ||
}) | ||
``` | ||
```js | ||
const yaml = new YAML({ | ||
type: "array", | ||
element: { | ||
type: "string" | ||
}, | ||
length?: { | ||
min?: number, | ||
max?: number | ||
} | ||
}) | ||
``` | ||
`object` schema: | ||
```js | ||
const yaml = new YAML({ | ||
type: "object", | ||
props: { | ||
name: schema | ||
} | ||
}) | ||
``` | ||
```js | ||
const yaml = new YAML({ | ||
type: "object", | ||
props: { | ||
name: { | ||
type: "string", | ||
length: { | ||
max: 100 | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
or | ||
```js | ||
const yaml = new YAML({ | ||
type: "object", | ||
any: { | ||
interface: schema, | ||
length?: { | ||
min?: number, | ||
max?: number | ||
} | ||
} | ||
}) | ||
``` | ||
```js | ||
const yaml = new YAML({ | ||
type: "object", | ||
any: { | ||
interface: { | ||
type: "number", | ||
limit: { | ||
min: 10, | ||
max: 100 | ||
} | ||
}, | ||
length?: { | ||
min?: number, | ||
max?: number | ||
} | ||
} | ||
}) | ||
``` |
Oops, something went wrong.