normik
v1.0.2
Published
<p align="center" style="font-weight: bold; font-size: 20px;"> Fast and simple library for convert your data from server to store and backward.
Downloads
3
Readme
normik
Installation
npm install normik --save
If you find bag, please create ISSUE.
Scheme structure
[
[field_name_server, field_name_client?, default_value?],
[field_name_server, field_name_client?, default_value?],
/// other fields
]
If not field_name_client will be set default field_name_server.
If you need set default value, but don't need set field_name_client, plese set
field_name_client = "";
If you need usage nesting, please use dot in field name
money.now
{
...other data
money: {
now: $value$
}
}
Example usage
Example scheme convert
const scheme = [
["user_name", "userName"],
["age"],
["money.now", "moneyNow", 0],
["email", "", null],
["phones", "phone.bob"]
];
Example data from server
const data = {
"user_name": "bob",
"age": 7,
"money": {
"now": 10
},
"phones": [7914, 8914]
}
Convert from server
import { norm2Store } from "normik";
const res = norm2Store(data, scheme);
Result
{
"userName": "bob",
"age": 7,
"moneyNow": 10,
"email": null,
"phone": {
"bob": [7914, 8914]
}
}
Convert result to server
import { norm2Server } from "normik";
const res = norm2Server(data, scheme);
Result
{
"user_name": "bob",
"age": 7,
"money": {
"now": 10
},
"email": null,
"phones": [7914, 8914]
}