ostrio:jsextensions

v0.0.2Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Useful Object Extensions for Meteor

Date:

  • Date.now() - Fix for ES if Date object has not now() method

Math:

  • Math.getRandom(min, max) - Get random number between max and min values, by default max is 1000 and min is 0

Object

  • Object.defineReactiveProperty(target, prop, value, callback, getCallback, setCallback) - define Reactive property with callbacks:
    • set callback before Setter and Getter
    • set callback on Setter
    • set callback on Getter
  • inArray(needle, searchInKey, searchByKey) - Extend Object prototype within inArray function
  • someObj.walk(callback) - Extend Object prototype within walk function callback, callback(object, value, key){}
  • Object.Merge - Merge the enumerable attributes of two objects deeply
  • someArray.random() - Extend Object prototype within random value pick up functionality for arrays

RegExp:

  • RegExp.escape(string) - Function is used to escape all dangerous/reserved symbols in strings before creating RegExp with it

String:

  • String.generate(length, symbols) - Generate random string from 1 to 10 symbols length, or with provided length, and made of provided symbols
  • someString.clone() - Clone (a.k.a. create singleton) of String object. This method allows to resolve issue with variable's referencing. See performance here

clone() example:

1var str = 'abc';
2var str2 = str.clone();
3str = 'cde';
4console.log(str2); //-> 'abc'