Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
brighthas-model
Advanced tools
npm i brighthas/model --save
var createModel = require("model");
var User = createModel("User",
"name",
"age",
history,{type:"array"});
User
.attr("name")
.attr("age")
.attr("history",{type:"array"});
User.method("getUserInfo",function(){
return "Name : " + this.name + "\n Age : " + this.age;
});
var user = new User({ name:"leo" , age:20 , history: [] });
user.begin(); // begin update
user.name = "brighthas";
user.age = 30;
user.end(); // end update , then may emit 'changed' event.
user.begin(); // begin update
user.name = "brighthas";
user.age = 30;
user.end(); // end update , then may emit 'changed' event.
console.log(this.hasError()); // true / false
console.log(this.errors); // [] is no error .
or
user.begin();
user.set({name:"leo",age:25});
user.end(); // end update , then may emit 'changed' event.
console.log(this.hasError()); // true / false
console.log(this.errors); // [] is no error .
or no use begin() & end()
user.name = 222 ;
console.log(this.hasError()); // true
// if have error , then can't change other value.
user.age = 16 ;
console.log(user.age) ; // no 16.
// so first clear errors.
user.errors = [];
user.age = 16;
console.log(user.age); // 16
var jsonObj = user.toJSON();
var user2 = User.reborn(jsonObj); console.log(user.name === user2.name); // true
user2.name = "brighthas"; console.log(user.name === user2.name); // false
if no assign type , default type="string" .
Two types : value type
and complex type
.
string
| array
| json
| boolean
| number
| date
| regexp
when get value , the value is clone .
var T = createModel("T",ts:{type:"json"});
var t = T();
t.userInfo = {name:"leo"};
var u1 = t.userInfo;
var u2 = t.userInfo;
console.log(u1 === u2); // false
complex type can be Model
or object including Type.prototype.toJSON & Type.reborn function & emit changed
event.
when get value , the value is original value.
var User = createModel("User",
"name",
"age",
history,{type:"array"});
var T = createModel("T",user:{type:User}); // User is Model.
var t = T();
t.user = User({name:"leo",age:21});
var u1 = t.user; // the value is original value.
var u2 = t.user; // the value is original value.
console.log(u1 === u2); // true ,
or
function User(name,age,hisitory){
this.name = name;
this.age = age;
this.history = hisitory || [];
}
User.prototype.toJSON = function(){
return {
name:this.name,
age:this.age,
history:this.history
}
}
User.reborn = function(jsonObj){
return new User(jsonObj.name,jsonObj.age,jsonObj.history);
}
//////////////////////////////////////////
var T = createModel("T",user:{type:User});
var t = T();
t.user = User("leo",21);
var u1 = t.user; // the value is original value.
var u2 = t.user; // the value is original value.
console.log(u1 === u2); // true ,
FAQs
model for javascript
We found that brighthas-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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.