Socket
Socket
Sign inDemoInstall

mol-proto

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.3 to 0.1.4

2

bower.json
{
"name": "proto",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "https://github.com/MailOnline/proto",

@@ -5,0 +5,0 @@ "authors": [

@@ -12,2 +12,3 @@ 'use strict';

* - [prependArray](#prependArray)
* - [spliceItem](#spliceItem)
* - [toArray](#toArray)

@@ -30,3 +31,4 @@ * - [object](#object)

unique: unique,
deepForEach: deepForEach
deepForEach: deepForEach,
spliceItem: spliceItem
};

@@ -115,2 +117,17 @@

/**
* Removes item from array that is found using indexOf (i.e. '===')
* Modifies original array and returns the reference to it.
*
* @param {Array} self An array that will be modified
* @param {Any} item item to be removed
* @return {Array}
*/
function spliceItem(item) {
var index = this.indexOf(item);
if (index >= 0) this.splice(index, 1);
return this;
}
/**
* Returns new array created from array-like object (e.g., `arguments` pseudo-array).

@@ -117,0 +134,0 @@ *

@@ -15,2 +15,4 @@ 'use strict';

* - [defer](#defer)
* - [delayed](#delayed)
* - [deferred](#deferred)
* - [deferTicks](#deferTicks)

@@ -32,2 +34,4 @@ * - [delayMethod](#delayMethod)

defer: defer,
delayed: delayed,
deferred: deferred,
deferTicks: deferTicks,

@@ -214,2 +218,37 @@ delayMethod: delayMethod,

/**
* Returns function that will execute the original function `wait` ms after it has been called
* The context in function when it is executed is set to `null`.
*
* @param {Function} self function which execution has to be deferred
* @param {Number} wait approximate dalay time in milliseconds
* @param {List} arguments optional arguments that will be passed to the function
* @return {Function}
*/
function delayed(wait) { //, ... arguments
var func = this
, args = slice.call(arguments, 1);
return function() {
return _delay(func, wait, args);
}
}
/**
* Returns function that will execute the original function on the next tick once it has been called
* The context in function when it is executed is set to `null`.
*
* @param {Function} self function which execution has to be deferred
* @param {List} arguments optional arguments that will be passed to the function
* @return {Function}
*/
function deferred() { //, ... arguments
var func = this
, args = arguments;
return function() {
return _delay(func, 1, args);
}
}
/**
* Creates a function that will call original function once it has not been called for a specified time

@@ -216,0 +255,0 @@ *

@@ -14,3 +14,5 @@ 'use strict';

* - [deepClone](#deepClone)
* - [keys](#keys)
* - [allKeys](#allKeys)
* - [values](#values)
* - [keyOf](#keyOf)

@@ -38,3 +40,5 @@ * - [allKeysOf](#allKeysOf)

deepClone: deepClone,
keys: keys,
allKeys: allKeys,
values: values,
keyOf: keyOf,

@@ -129,2 +133,3 @@ allKeysOf: allKeysOf,

function clone() {
if (Array.isArray(this)) return this.slice();
var clonedObject = Object.create(this.constructor.prototype);

@@ -281,2 +286,30 @@ extend.call(clonedObject, this);

/**
* Returns array of enumerable properties of the object
*
* @param {Object} self object to return keys of
* @return {Array}
*/
function keys() {
return Object.keys(this);
}
/**
* Returns array of values of the object's keys
*
* @param {Object} self object to return values from
* @return {Array}
*/
function values(onlyEnumerable) {
var properties = onlyEnumerable
? Object.keys(this)
: allKeys.call(this);
return properties.map(function(prop) {
return this[prop];
}, this);
}
/**
* Returns array of all property names of an object `self` (including non-enumerbale).

@@ -283,0 +316,0 @@ * To get only enumerable properties, use `Object.keys()`.

@@ -13,2 +13,6 @@ 'use strict';

* - [toDate](#toDate)
* - [toQueryString](#toQueryString)
* - [fromQueryString](#fromQueryString)
* - [jsonParse](#jsonParse)
* - [hashCode](#hashCode)
*/

@@ -22,3 +26,5 @@ var stringMethods = module.exports = {

toQueryString: toQueryString,
fromQueryString: fromQueryString
fromQueryString: fromQueryString,
jsonParse: jsonParse,
hashCode: hashCode
};

@@ -137,1 +143,32 @@

}
/**
* Safe JSON.parse, returns undefined if JSON.parse throws an exception
*
* @param {String} self JSON string representation of object
* @return {Object|undefined}
*/
function jsonParse() {
try {
return JSON.parse(this);
} catch (e) {}
}
/**
* Dan bernstein's algorythm to create hash from string
*
* @param {String} self string to convert to hash
* @return {Number}
*/
function hashCode(){
var hash = 5381
, str = this
, len = str.length;
for (var i = 0; i < len; i++) {
var char = str.charCodeAt(i);
hash = ((hash << 5) + hash) + char; /* hash * 33 + c */
}
return hash;
}

@@ -25,3 +25,5 @@ 'use strict';

* - [deepClone](proto_object.js.html#deepClone)
* - [keys](proto_object.js.html#keys)
* - [allKeys](proto_object.js.html#allKeys)
* - [values](proto_object.js.html#values)
* - [keyOf](proto_object.js.html#keyOf)

@@ -50,2 +52,3 @@ * - [allKeysOf](proto_object.js.html#allKeysOf)

* - [prependArray](proto_array.js.html#prependArray)
* - [spliceItem](proto_array.js.html#spliceItem)
* - [toArray](proto_array.js.html#toArray)

@@ -71,2 +74,4 @@ * - [object](proto_array.js.html#object)

* - [defer](proto_function.js.html#defer)
* - [delayed](proto_function.js.html#delayed)
* - [deferred](proto_function.js.html#deferred)
* - [deferTicks](proto_function.js.html#deferTicks)

@@ -92,2 +97,4 @@ * - [delayMethod](proto_function.js.html#delayMethod)

* - [fromQueryString](proto_string.js.html#fromQueryString)
* - [jsonParse](proto_string.js.html#jsonParse)
* - [hashCode](proto_string.js.html#hashCode)
*/

@@ -189,3 +196,3 @@ var stringMethods = require('./proto_string');

// expose global _
// expose global _ and Proto
window._ = Proto;

@@ -192,0 +199,0 @@ }

{
"name": "mol-proto",
"version": "0.1.3",
"version": "0.1.4",
"description": "ES5 object manipulation library for node and modern browsers",

@@ -5,0 +5,0 @@ "main": "lib/proto.js",

@@ -66,3 +66,5 @@ proto

* [deepClone](http://mailonline.github.io/proto/proto_object.js.html#deepClone)
* [keys](http://mailonline.github.io/proto/proto_object.js.html#keys)
* [allKeys](http://mailonline.github.io/proto/proto_object.js.html#allKeys)
* [values](http://mailonline.github.io/proto/proto_object.js.html#values)
* [keyOf](http://mailonline.github.io/proto/proto_object.js.html#keyOf)

@@ -86,2 +88,3 @@ * [allKeysOf](http://mailonline.github.io/proto/proto_object.js.html#allKeysOf)

* [prependArray](http://mailonline.github.io/proto/proto_array.js.html#prependArray)
* [spliceItem](http://mailonline.github.io/proto/proto_array.js.html/proto_array.js.html#spliceItem)
* [toArray](http://mailonline.github.io/proto/proto_array.js.html#toArray)

@@ -101,2 +104,4 @@ * [object](http://mailonline.github.io/proto/proto_array.js.html#object)

* [defer](http://mailonline.github.io/proto/proto_function.js.html#defer)
* [delayed](http://mailonline.github.io/proto/proto_function.js.html#delayed)
* [deferred](http://mailonline.github.io/proto/proto_function.js.html#deferred)
* [deferTicks](http://mailonline.github.io/proto/proto_function.js.html#deferTicks)

@@ -118,2 +123,4 @@ * [delayMethod](http://mailonline.github.io/proto/proto_function.js.html#delayMethod)

* [fromQueryString](http://mailonline.github.io/proto/proto_string.js.html#fromQueryString)
* [jsonParse](http://mailonline.github.io/proto/proto_string.js.html#jsonParse)
* [hashCode](http://mailonline.github.io/proto/proto_string.js.html#hashCode)

@@ -120,0 +127,0 @@ * [__Number functions__](http://mailonline.github.io/proto/proto_number.js.html)

@@ -14,4 +14,3 @@ 'use strict';

assert.deepEqual(arr, [1, 2, 3, 4, 5, 6, 7],
'should add to the end of the array and change array in place');
assert.deepEqual(arr, [1, 2, 3, 4, 5, 6, 7]);
});

@@ -25,7 +24,16 @@

assert.deepEqual(arr, [4, 5, 6, 7, 1, 2, 3],
'should add to the beginnning of the array and change array in place');
assert.deepEqual(arr, [4, 5, 6, 7, 1, 2, 3]);
});
it('should define spliceItem function', function() {
var arr = ['a', 'b', 'c'];
var result = _.spliceItem(arr, 'b');
assert.deepEqual(arr, ['a', 'c']);
assert.equal(result, arr);
});
it('should define toArray function', function() {

@@ -32,0 +40,0 @@ var arrayLikeObject = {};

@@ -177,2 +177,48 @@ 'use strict';

it('should define delayed function', function(done) {
var called, args;
function myFunc() {
called = true;
args = Array.prototype.slice.call(arguments);
}
var delayedFunc = _.delayed(myFunc, 10, 1, 2, 3);
delayedFunc();
assert.equal(called, undefined);
assert.equal(args, undefined);
setTimeout(function() {
assert.equal(called, true);
assert.deepEqual(args, [1, 2, 3]);
done();
}, 20);
});
it('should define deferred function', function(done) {
var called, args;
function myFunc() {
called = true;
args = Array.prototype.slice.call(arguments);
}
var deferredFunc = _.deferred(myFunc, 1, 2, 3);
deferredFunc();
assert.equal(called, undefined);
assert.equal(args, undefined);
setTimeout(function() {
assert.equal(called, true);
assert.deepEqual(args, [1, 2, 3]);
done();
}, 5);
});
it('should define deferTicks function', function(done) {

@@ -179,0 +225,0 @@ var called, args;

@@ -224,2 +224,21 @@ 'use strict';

it('should define keys, allKeys and values', function() {
var self = {
a: 1,
b: 2,
c: 3
};
Object.defineProperty(self, 'nonenum', {
enumerable: false,
value: 4
});
assert.deepEqual(_.keys(self), ['a', 'b', 'c']);
assert.deepEqual(_.allKeys(self), ['a', 'b', 'c', 'nonenum']);
assert.deepEqual(_.values(self), [1, 2, 3, 4]);
assert.deepEqual(_.values(self, true), [1, 2, 3]);
});
it('should define allKeysOf function', function() {

@@ -226,0 +245,0 @@ var self = {

@@ -76,2 +76,23 @@ 'use strict';

});
it('should define jsonParse', function() {
var json = '{"test":1, "name":"milo"}'
, badJson = '{"test:1';
assert.deepEqual(_.jsonParse(json), { test: 1, name: 'milo' });
assert.equal(_.jsonParse(badJson), undefined);
assert.throws(function() {
JSON.parse(badJson);
});
});
it('should define hashCode function', function() {
var result1 = _.hashCode('This was no small decision. Four generations of Orr men had been Eagles, including Ron and Andrew\'s older brother. Andrew had spent years working toward Scouting\'s highest rank, and was just months from reaching it.');
assert.equal(typeof result1, 'number');
var result2 = _.hashCode('But the Boy Scouts had decided to admit gays, and Ron Orr, a tall, soft-spoken man with a firm handshake, is clear about his Christian faith and what it says about homosexuality: It is a sin that cannot be tolerated.');
assert.equal(typeof result2, 'number');
assert(result1 != result2);
})
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc