Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.