
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Data model for javascript
npm install js-model --save
{
// when use dispose data, remove empty array.
removeEmptyArray: false,
// when use parse data, remove null value.
removeNull: false,
// remove null value from array.
removeNullFromArray: false,
// remove null value from object.
removeEmptyObject: true,
}
Model.S // money ten 十
Model.B // money hundred 百
Model.Q // money thousand 千
Model.W //money ten thousand 万
Model.SW // money one hundred thousand 十万
Model.BW // money million 百万
Model.QW // money ten million 千万
Model.Y // money billion 亿
parse:
dispose:
When you need to transfer the data to the background, convert the date into a timestamp, convert the amount to the amount in the unit, standardize the data format, and delete the empty data.
Example: the value modified by input is String, and is converted to digital format through dispose.
Basic.js
import Model from "js-model";
let Basic = new Model({
id: 0,
source: {
type: Date,
format: 'l' // use manba date format, "l": "YYYY-MM-DD",
},
description: "",
tags: [ 0 ],
companyId: "",
rate: {
type: Number,
default: 0.8 // use default value, only effective for String, Number, Date
},
salary: {
type: Number,
unit: Model.Q // money transfor, a unit of 1000
}
});
export default Basic;
Usage 1: fill property
import Basic from './Basic.js'
let basicValue = Basic.parse({});
basicValue:
{
id: null,
source: null,
description: null,
tags: [],
companyId: null,
rate: 0.8, // use default value
salary: null
}
Usage 2: conversion amount and date
import Basic from './Basic.js'
let basicValue = Basic.parse({
source: "2017-06-09T00:00:00+08:00",
salary: 10000,
rate: 0.1
});
basicValue:
{
id: null,
source: "2017-06-09", //
description: null,
tags: [],
companyId: null,
rate: 0.1,
salary: 10 //10000 conversion to a thousand units
}
Usage 1: remove null property
import Basic from './Basic.js'
let basicValue = Basic.dispose({
id: null,
source: "2017-06-09",
description: null,
tags: [],
companyId: null,
rate: "0.1",
salary: 10
});
basicValue: Consistent with the values converted from parse
{
source: "2017-06-09T00:00:00+08:00",
salary: 10000,
rate: 0.1
}
// Basic.js
let Basic = new Model({
id: 0,
companyId: "",
rate: 0
});
export default Basic;
// Edu.js
let Edu = new Model({
id: 0,
major: "",
school: ""
});
export default Edu;
// User.js
import Edu from "./Edu";
import Basic from "./Basic";
let User = new Model({
basic: Basic,
edu: [Edu]
});
export default User;
import User from './User'
let user = User.parse({
basic:{
id:123123
},
edu:[{
id: 12
}],
})
result:
{
basic: {
id: 123123,
companyId: null,
rate: null
},
edu: [{
id: 12,
school: null
major: null,
}]
}
import User from './User'
let user = User.dispose({
basic:{
id:123123,
companyId: 123,
rate: null
},
edu:[{
id: 12,
school: "school"
major: null,
}],
})
result:
{
basic: {
id:123123,
companyId: 123,
},
edu: [{
id: 12,
school: "school"
}]
}
const info = new InfoModel({
salary: {
type: Number,
parse(data) {
return data.salary / 1000
},
dispose(data) {
return data.salary * 1000
}
},
});
info.parse({salary: 10000})
// {salary: 10}
info.parse({salary: 20})
// {salary: 20000}
class InfoModel extends Model {
parse(data) {
let b = super.parse(data);
if(b.imgUrls.type.length == 0) {
b.imgUrls.type.push('http://*****')
}
return b;
}
dispose(data, param) {
return super.dispose(data, param)
}
}
const info = new InfoModel({
imgUrls: {
type: ['']
},
});
info.parse({})
result:
{
imgUrls: {
type: ['http://*****']
},
}
manba-config.js The default is the ISO date format of the current time zone, for example: 2016-04-19T00:00:00+08:00
import Model from 'js-model';
// Redefining the format of the date conversion
Model.config({
disposeDateFormat(date) {
// change to use timestamp
return manba(date).time();
}
})
FAQs
model for javascript
We found that js-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.