🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

nativemodels

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativemodels - npm Package Compare versions

Comparing version
2.4.0
to
2.4.1
+7
-0
datatypes/string.js

@@ -24,4 +24,11 @@ const createType = require('./../createType');

},
validCheck: (key, value) => {
if (value === null) {
throw new Error(`NativeModels - Property ${key} is not a string`);
}
return true;
},
});
module.exports = string;
+7
-9
const defaultRecord = (schema, record) => ({
...Object.keys(schema)
.filter((key) => schema[key].hasDefault)
.reduce(
(result, key) => ({
...result,
...{ [key]: schema[key].defaultValue },
}),
{},
),
...record,
...Object.keys(schema).reduce(
(result, key) => ({
...result,
...(schema[key].hasDefault ? { [key]: record[key] || schema[key].defaultValue } : {}),
}),
{},
),
});
module.exports = defaultRecord;

@@ -13,2 +13,3 @@ {

"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-react": "^7.12.4",
"husky": "^1.2.0",

@@ -32,7 +33,12 @@ "jest": "^23.6.0",

"lint-staged": {
"*.js": [
"eslint --fix",
"prettier --config ./.prettierrc.json --write",
"jest --bail --findRelatedTests",
"git add"
"linters": {
"*.js": [
"eslint --fix",
"prettier --config ./.prettierrc.json --write",
"jest --bail --findRelatedTests",
"git add"
]
},
"ignore": [
"site/**"
]

@@ -54,3 +60,3 @@ },

},
"version": "2.4.0"
"version": "2.4.1"
}

@@ -37,2 +37,6 @@ <h1 align="center">

<!-- CircleCI -->
[![Build Status](https://flat.badgen.net/circleci/Prefinem/nativemodels)](https://circleci.com/gh/Prefinem/nativemodels)
<!-- CodeCov -->

@@ -155,2 +159,20 @@

### datatypes.from(fromKeys, options)
When passing in an object that you would like a key renamed, you can set the correct name in the schema and set the from to key name on the original object. This is useful for renaming and recasing.
```js
const { createModel } = require('nativemodels');
const { string } = require('nativiemodels/datatypes');
const schema = {
name: string().from('firstName'),
};
const model = createModel(schema);
const user = model({ firstName: 'john' });
console.log(user.name);
// => 'john'
```
## Datatypes

@@ -157,0 +179,0 @@