0.1.4 • Published 10 years ago

object-getset v0.1.4

Weekly downloads
2
License
MIT
Repository
-
Last release
10 years ago

#Object Get/Set A simple module for safely - accessing / modifying - chained properties on objects without the unnecessary hassle.

Current Version: 0.1.4 Tested with Node: 0.10.20 >= Tested with REQUIREJS: 2.1.8 >=

Features:

  • Lightweight and Efficient
  • AMD support
  • NPM published
  • Abstracted into module to prevent global issues (unless not using module system)
  • Speed optimized
  • Quick and efficient property accesses.
  • We need battle-testers.

#Install/Require:

In-line Script:

Add getset.js to html page

<script type="text/javascript" src="getset.js"></script>

AMD:

If you are using require.js or AMD you can require getset.

require(['getset'], function(GetSet) {
  console.log(GetSet);
});

Node:

Add getset.js to project folder and require

var GetSet = require('./getset');
console.log(GetSet);

NPM (Node) - Link:

Install the module [sudo] npm install -g object-getset or npm install object-getset

var GetSet = require('object-getset');
console.log(GetSet);

#Example: View the index.html in the example/ folder for use and examples (both global and requirejs AMD).

#Methods: When not using a module system (node, requirejs, amd), getset will expose getProperty and setProperty methods to the global name-space (mainly browser environment); otherwise, it will provide the methods on an exported object.

#Documentation:

GetSet provides two methods for handling objects.

getProperty(object, string);

Safely accesses a chained property on an object; useful for complex if statements without throwing an error due to an access attempt on a property of an undefined object

Arguments:

    1. object: The object to search.
    1. string: The string containing a chained value of the value desired. e.g. 'kitchen.sink'.

Returns:

  • (Any object type): Returns the value of the specified chained value; otherwise, will return undefined. e.g. object, string, array, boolean, null, undefined

Example:

getProperty({classes: {semesters: 3}}, 'classes.semesters');

setProperty(object, string, value);

Safety - modifies/creates - a chained property on an object; useful for adding complex chained values without creating prior objects. Will completely avoid throwing an error when setting a property of an undefined object. Quick and easy.

Arguments:

    1. object: The object to set a value upon.
    1. string: The string containing a chained value e.g. 'kitchen.sink'.
    1. value (any object type): The desired value.

Returns:

  • (Object): Returns the object supplied, always; will be the modified version.

Example:

setProperty({classes: {semesters: 3}}, 'classes.semesters', 4);

#Log:

V0.1.3 - (10/31/13):

  • Re-factor of setProperty to only create object property if it doesn't exist. Otherwise, it will recognize the object, preserve it, and simply add the supplied data

v0.1.2 - (10/30/13):

  • Re-factor of setProperty method to support defining undefined properties in objects
  • Consistency with getProperty: better support of false values (will now return undefined if property accessed is not present or property searched is not an object)
  • Stability and more simple setProperty method

v0.1.1 - (10/14/13):

  • Updated documentation - (spelling)
  • Cleaned comments
  • Changed program variables
  • Simple re-factor - stability enhancement

v0.1.0-B1 - (10/13/13):

  • Initial Commit