JSPM

madlib-object-utils

0.1.8
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q55681F

A small set of utility functions for working with objects

Package Exports

  • madlib-object-utils
  • madlib-object-utils/lib/utils.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (madlib-object-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

madlib-object-utils

Build Status NPM version Built with Grunt

Npm Downloads

A small set of utility functions for working with objects

acknowledgments

The Marviq Application Development library (aka madlib) was developed by me when I was working at Marviq. They were cool enough to let me publish it using my personal github account instead of the company account. We decided to open source it for our mutual benefit and to ensure future updates should I decide to leave the company.

philosophy

JavaScript is the language of the web. Wouldn't it be nice if we could stop having to rewrite (most) of our code for all those web connected platforms running on JavaScript? That is what madLib hopes to achieve. The focus of madLib is to have the same old boring stuff ready made for multiple platforms. Write your core application logic once using modules and never worry about the basics stuff again. Basics including XHR, XML, JSON, host mappings, settings, storage, etcetera. The idea is to use the tried and proven frameworks where available and use madlib based modules as the missing link.

Currently madLib is focused on supporting the following platforms:

  • Web browsers (IE6+, Chrome, Firefox, Opera)
  • Appcelerator/Titanium
  • PhoneGap
  • NodeJS

installation

$ npm install madlib-object-utils --save

usage

var objectUtils = require( "madlib-object-utils" )

var myObject     =
{
    books:
    {
        book: [
            "Example book 1",
            "Example book 2"
        ]
    }
}

// Retrieve a value from an object
// Will return 'Example book 1'
// 3rd parameter will be return if the path can't be found
//
book1Name = objectUtils.getValue( "books.book.0", myObject, "unknown" )

// Set a value on an object
// Will update 'Example book 2' to 'Example book 2a'
//
objectUtils.setValue( "books.book.1", myObject, "Example book 2a" )

// Retrieve a value from an object and creates is if it doesn't exist
//
book3 = objectUtils.getAndCreate( "books.book.2", myObject, "Example book 3" )

// Check if something is an array
//
books = objectUtils.getValue( "books.book", myObject )
if ( objectUtils.isArray( books ) )
{
    books.push( "Example book 4" )
}