Skip to content

Commit

Permalink
Merge pull request #162 from hckrnews/feature/finetune-mapping
Browse files Browse the repository at this point in the history
Feature/finetune mapping
  • Loading branch information
w3nl authored Feb 1, 2022
2 parents 6c3603a + 1131196 commit 8c31e5d
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 72 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ flatter.flatSome((x) => x === 2)
true
```

For arrays you can also use `createAll` and `parseAll`.
It works the same as `create` and `parse` but it can do it on every item in an array.

[npm-url]: https://www.npmjs.com/package/@hckrnews/objects
[npm-image]: https://img.shields.io/npm/v/@hckrnews/objects.svg
[scrutinizer-url]: https://scrutinizer-ci.com/g/hckrnews/objects/?branch=master
Expand Down
138 changes: 69 additions & 69 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hckrnews/objects",
"description": "Create valid JavaScript objects",
"version": "3.5.0",
"version": "3.6.0",
"author": {
"name": "Pieter Wigboldus",
"url": "https://hckr.news/"
Expand All @@ -15,7 +15,7 @@
"test:watch": "jest src --watch",
"coveralls": "jest && codecov && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"cpd": "node_modules/jscpd/bin/jscpd src",
"vulnerabilities": "npm audit --only=prod"
"vulnerabilities": "npm audit --production"
},
"type": "module",
"files": [
Expand All @@ -35,7 +35,7 @@
"babel-jest": "^27.2.4",
"codecov": "^3.6.5",
"coveralls": "^3.0.13",
"eslint": "^8.3.0",
"eslint": "^8.8.0",
"eslint-config-airbnb": "^19.0.1",
"eslint-config-prettier": "^8.2.0",
"eslint-plugin-html": "^6.1.2",
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/create-all.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, describe, it } from '@jest/globals';
import Obj from '../objects.js';

const schema = {
sku: String
}
const ObjectWithSchema = Obj({ schema });

describe('Test createAll', () => {
it('It should create an object for all items', () => {
const data = [
{ sku: '123' },
{ sku: '124' },
]
const result = ObjectWithSchema.createAll(data);
expect(result).toEqual(data);

const keys = result.map(item => item.keys());
expect(keys).toEqual([
['sku'],
['sku']
]);
});
});
22 changes: 22 additions & 0 deletions src/__tests__/parse-all.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect, describe, it } from '@jest/globals';
import Obj from '../objects.js';

const schema = {
sku: Number
}
const ObjectWithSchema = Obj({ schema });

describe('Test parseAll', () => {
it('It should parse the object for all items', () => {
const data = [
{ sku: '123' },
{ sku: '124' },
]
const result = ObjectWithSchema.parseAll(data);
const expected = [
{ sku: 123 },
{ sku: 124 },
]
expect(result).toEqual(expected);
});
});
Loading

0 comments on commit 8c31e5d

Please sign in to comment.