A utility to create instantiateable objects with simple getters and setters. Cleaner syntax, typo-proof code.

Downloads in past


312.0.17 years ago11 years agoMinified + gzip package size for strict-object in KB


strict-object ##

A utility that makes it safer and prettier to deal with javascript objects that have a defined set of properties. Status: Build Status

Installing ###

strict-object is compatable with npm, browsers, windows script host,and probably more. ``` npm install strict-object ``` When minified, strict-object.js ends up less than 400 bytes.

What ###

```javascript // Create a new person type var Person = StrictObject.define('name', 'age', 'country'); // Instatiate a Person var pete = new Person(); // set properties using functions'Peter'); // get properties using functions console.log(; // property setters return the target object and are thus chainable'Peter')
// retrieve the properties as an object console.log(pete.toObject()); // {name: 'Peter', age: 26, country: 'Uzbekistan'} // Instatiate a Person with initial values var pete = new Person({
name: "Peter",
age: 26,
country: "Uzbekawhat?"
}); ```

Running Tests ###

``` npm test ```

Why ###

Because typos are too easy with basic objects. ```javascript var thing = {}; thing.descriptivePropertyName = 'value'; console.log(thing.descriptvePropertyName); // null -- because of a typo. ``` Syntax is ugly with basic objects ```javascript var thing = {
key: "value",
key2: "value2"
}; ``` Cleaner and safer with strict-object ```javascript thing = new Thing()

License ###

No License, the content of this repository is in the public domain, no attribution is necessary.