Skip to content

Commit

Permalink
Update the readme
Browse files Browse the repository at this point in the history
And update dependencies
  • Loading branch information
w3nl committed Jul 23, 2021
1 parent 2286925 commit 48ca573
Show file tree
Hide file tree
Showing 9 changed files with 4,147 additions and 6,298 deletions.
9 changes: 2 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
"node": true,
"browser": true
},
"globals": {
"describe": false,
"it": false,
"expect": false
},
"extends": [
"@hckrnews/eslint-config"
],
"parserOptions": {
"sourceType": "module",
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"babelOptions": {
"configFile": "babel.config.js",
"configFile": "./babel.config.cjs"
}
},
"overrides": [
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- name: npm install, lint, and test
run: |
npm ci
npm run vulnerabilities
npm run lint
npm test
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
with:
node-version: 12
- run: npm ci
- run: npm run vulnerabilities
- run: npm run lint
- run: npm test

publish-npm:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ yarn-error.log*
*.njsproj
*.sln
*.sw?
.dccache
88 changes: 86 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Hack JavaScript objects
# Create valid JavaScript objects

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Scrutinizer Code Quality][scrutinizer-image]][scrutinizer-url]

Get a flat version of the object
Create objects and validate the values, so you know all values are ok.
You don't have to create code to validate all fields of an object, just write a schema.
Also get more usefull methods to work with objects.

## Installation

Expand All @@ -16,10 +18,16 @@ or
or
`yarn test`

## Validation

For validation, it use the package `@hckrnews/validation` (https://github.com/hckrnews/validator)

## Usage

Example usage:
```javascript
import Obj from '@hckrnews/objects'

const addressSchema = {
street: String,
number: Number,
Expand Down Expand Up @@ -49,6 +57,82 @@ console.log(myAddress)
}
```

You can also define sub schemas:

```javascript
import Obj from '@hckrnews/objects'

const filterSchema = {
key: String,
type: String
}

const optionSchema = {
value: String,
'count?': Number
}

const selectFilterSchema = {
...filterSchema,
options: optionSchema
}

const SelectFilter = Obj({ schema: selectFilterSchema })

const multiselect = SelectFilter.create({
key: 'status',
type: 'multiselect',
options: [
{
value: 'open',
count: 42
},
{
value: 'closed'
}
]
})

console.log(multiselect)

{
street: 'status',
number: 'multiselect',
options: [
{
value: 'open',
count: 42
},
{
value: 'closed'
}
]
}
```

Catching validation errors:

```javascript
try {
const multiselect = SelectFilter.create({
key: 'status',
options: [
{
value: 'open',
count: 42
},
{
value: 'closed'
}
]
})
} catch (error) {
console.log(error.message)
}

'The field type should be a String'
```

Example usage without a schema:
...

Expand Down
Loading

0 comments on commit 48ca573

Please sign in to comment.