Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
ClazzJS is portable JavaScript library for class-style OOP programming. Its main goal is to provide expressive DSL to write your JavaScript programs in easy-to-understand, well-known, convenient and flexible class base manner. It's works well both on client and server sides.
Features include:
You'll find the example bellow to have a common idea what I'm talking about.
This docs describe many features of the library, but not all. Use source to learn ClazzJS better. In every doc chapter there are links on respective source files.
Main goal of this example is to give you a common idea about ClazzJS. It's not discover all features of the library. Online working version of this example is available on plunker: http://plnkr.co/edit/c5Xveb. Feel free to play around with it!
Person
clazz declaration:
clazz("Person", {
constants: {
SEX: ['male', 'female']
},
properties: {
name: {
type: 'string',
methods: ['get']
},
phone: {
type: ['string', {
pattern: /\d{1,2}-\d{3}-\d{5,7}/
}]
},
birthday: {
type: 'datetime',
constratins: {
inPast: function(birthday) {
return birthday.getTime() < Date.now();
}
}
},
sex: {
type: 'string',
methods: ['get', 'set', 'is'],
converters: {
toFull: function(sex) {
switch(sex.toLowerCase()) {
case 'm': sex = 'male'; break;
case 'f': sex = 'female'; break;
}
return sex;
}
},
constraints: {
existedSex: function(sex) {
return -1 !== this.const('SEX').indexOf(sex);
}
}
}
},
methods: {
getAge: function() {
return (new Date()).getFullYear() - this.getBirthday().getFullYear();
}
}
});
Teacher
clazz inherited from Person
:
clazz('Teacher', 'Person', {
constants: {
SUBJECT: ['physics', 'literature', 'mathematics']
},
properties: {
subject: {
type: 'string',
constraints: {
existedSubject: function(subject) {
return -1 !== this.const('SUBJECT').indexOf(subject);
}
}
}
}
});
Creation and manipulation of instances:
// Create just common person - John (without 'new' operator)
var john = clazz('Person').create({
name: 'John Stewart',
sex: 'M',
phone: '1-925-123567',
birthday: "1989-12-13"
});
john instanceof clazz("Person"); // true
john.getName(); // 'John Stewart'
john.getAge(); // 24
john.getSex(); // 'male'
john.getPhone(); // 1-925-123567
john.setPhone('7-925-1'); // Throw phone pattern fail error with message:
// 'Value "7-925-1" does not match
// pattern "/\d{1,2}-\d{3}-\d{5,7}/"'
john.isSex("male"); // true
john.isSex("female"); // false
john.setSex('unsupportedSex'); // Throw existedSex constraint fail error with message:
// 'Constraint "existedSex" was failed!'
john.setSex('female'); // Successfully change sex of John
john.getSex(); // 'female'
john.isSex("male"); // false
john.isSex("female"); // true
john.getBirthday() instanceof Date; // true
john.getBirthday().getMonth(); // 12
john.getBirthday().getFullYear(); // 1989
// Create math teacher - Mr. George Smith. (with 'new' operator)
var mathTeacher = new clazz('Teacher')({
name: 'George Smith',
sex: 'male',
birthday: '1973-12-34',
subject: 'mathematics'
});
mathTeacher instanceof clazz('Person'); // true
mathTeacher instanceof clazz('Teacher')); // true
mathTeacher.getName(); // John Smith
Copyright (c) 2013 Aleksey Podskrebyshev. Licensed under the MIT license.
FAQs
Portable JavaScript library for class-style OOP programming
The npm package clazz-js receives a total of 2 weekly downloads. As such, clazz-js popularity was classified as not popular.
We found that clazz-js 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 researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.