Socket
Socket
Sign inDemoInstall

protoblast

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protoblast - npm Package Compare versions

Comparing version 0.1.12 to 0.2.0

lib/request.js

23

CHANGELOG.md

@@ -0,1 +1,24 @@

## 0.2.0 (2016-05-02)
* Minor version bump because of added namespaces to `Function.inherits`
* `JSON.clone` will now also look for `#dryClone(wm)` and `#clone()` methods
* `JSON.clone` second parameter is an optional method name to use for cloning
* Fix bug in `JSONPath`
* `String#fillPlaceholders` can now remove used values from the given object
* Add `Date#setTimestring` to set the time in order of '12:00:00'
* The date 't' format should now return the number of days in the given month
* Added `JSON.safeParse`
* `Function.hinder` can now call pushed tasks with an error and other data
* `toDry` methods no longer need to return a 'path' property for undrying
* When the function passed to `Object.walk` returns false, it won't recurse
* Added `Object.getPropertyDescriptor`, which will look for a descriptor
up the prototype chain
* Getter and setter functions will now also receive a `super` property
reference to the function they're overriding
* `Function.setStatic` properties can now be overwritten
* `Function.setStatic` can now optionally not be inherited
* Add `Blast.createObjectId` for the browser
* Checksumming a null value won't throw an error anymore
* `Object.merge` should now correctly assign objects over primitive values
## 0.1.12 (2016-02-03)

@@ -2,0 +25,0 @@

module.exports = function BlastBrowserShims(Blast, Collection) {
var machine_id,
process_id,
counter = ~~(Math.random() * 10000);
var stringifyPrimitive = function(v) {

@@ -213,2 +217,53 @@ if (typeof v === 'string')

/**
* Create an ObjectID string
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 0.2.0
*
* @return {String}
*/
Blast.createObjectId = function createObjectId() {
var result,
count,
time;
// Start with 4 bytes for the time in seconds
time = parseInt(Date.now()/1000).toString(16).slice(0, 8);
result = time;
// Add the machine identifier
if (!machine_id) {
machine_id = Math.abs(Blast.Bound.String.fowler(navigator.userAgent)).toString(16);
if (machine_id.length < 6) {
machine_id += result;
}
// Get the first 6 pieces
machine_id = machine_id.slice(0, 6);
}
result += machine_id;
if (!process_id) {
process_id = Blast.Classes.Crypto.pseudoHex().slice(0, 4);
}
result += process_id;
// Create the counter
count = (counter++).toString(16);
if (count.length < 6) {
count = Blast.Bound.String.multiply('0', 6 - count.length) + count;
}
result += count;
return result;
};
};

2

lib/date_format.js

@@ -206,3 +206,3 @@ /**

methods.n = function() { return this.getMonth() + 1; };
methods.t = function() { var d = new Date(); return new Date(d.getFullYear(), d.getMonth(), 0).getDate() };
methods.t = function() { var d = this; return new Date(d.getFullYear(), d.getMonth(), 0).getDate() };

@@ -209,0 +209,0 @@ // Year

@@ -150,2 +150,34 @@ module.exports = function BlastDate(Blast, Collection) {

/**
* Set the hours/minutes/seconds using a string
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 0.2.0
*
* @return {Date}
*/
Blast.definePrototype('Date', 'setTimestring', function setTimestring(string) {
var pieces = string.split(':');
if (pieces[0]) {
this.setHours(pieces[0]);
}
if (pieces[1]) {
this.setMinutes(pieces[1]);
} else {
this.setMinutes(0);
}
if (pieces[2]) {
this.setSeconds(pieces[2]);
} else {
this.setSeconds(0);
}
return this;
});
/**
* Add a unit of time to the current date

@@ -304,3 +336,3 @@ *

* @since 0.1.4
* @version 0.1.4
* @version 0.2.0
*

@@ -322,3 +354,3 @@ * @param {String} unit year, quarter, month, week, day, ...

start = new Date(start);
end = new Date(end);
end = new Date(end || start);

@@ -325,0 +357,0 @@ if (unit != null) {

@@ -364,2 +364,28 @@ module.exports = function BlastDeck(Blast, Collection) {

/**
* Get a dictionary
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 0.2.0
*
* @return {Object}
*/
Deck.setMethod(function getDict() {
var result = {},
sorted = this.getSortedItems(),
entry,
i;
for (i = 0; i < sorted.length; i++) {
entry = sorted[i];
// Set the key-val
result[entry.key] = entry.value;
}
return result;
});
/**
* Get the sorted values

@@ -366,0 +392,0 @@ *

@@ -677,3 +677,3 @@ module.exports = function BlastFunctionFlow(Blast, Collection) {

* @since 0.1.4
* @version 0.1.11
* @version 0.2.0
*/

@@ -684,2 +684,3 @@ Blast.defineStatic('Function', 'hinder', function hinder(forceAsync, worker, options) {

finished,
result,
tasks,

@@ -718,5 +719,8 @@ done,

tasks: tasks,
onerror: null,
push: function push(task) {
if (finished) {
scheduler(task);
scheduler(function doTask() {
task.apply(obj, result);
});
} else {

@@ -734,4 +738,12 @@ tasks.push(task);

result = [];
for (i = 0; i < arguments.length; i++) {
result.push(arguments[i]);
}
if (err != null) {
throw err;
if (obj.onerror) {
obj.onerror(err);
}
}

@@ -742,3 +754,3 @@

for (i = 0; i < tasks.length; i++) {
tasks[i]();
tasks[i].apply(obj, result);
}

@@ -749,3 +761,3 @@ };

scheduler(function doWorker() {
worker(done);
worker.call(obj, done);
});

@@ -752,0 +764,0 @@

module.exports = function BlastInheritance(Blast, Collection) {
var Obj = Blast.Collection.Object;
/**

@@ -64,12 +66,16 @@ * Add a static method/property to the staticChain.

* @since 0.1.3
* @version 0.1.11
* @version 0.2.0
*
* @param {Function} newConstructor
* @param {String|Function|Array} _parent Parent class to inherit from
* @param {String} _namespace Namespace to store class in
* @param {Function} _newConstructor New class constructor
*
* @return {Function} newConstructor
* @return {Function}
*/
Blast.defineStatic('Function', 'inherits', function inherits(_newConstructor, _superConstructor) {
Blast.defineStatic('Function', 'inherits', function inherits(_parent, _namespace, _newConstructor) {
var superConstructor = _superConstructor,
var parentConstructor = _parent,
newConstructor = _newConstructor,
targetPath,
namespace = _namespace,
multiple,

@@ -79,31 +85,63 @@ names,

chain,
name,
path,
temp,
key,
i;
if (typeof newConstructor === 'string') {
names = [];
if (arguments.length == 1) {
newConstructor = parentConstructor;
parentConstructor = null;
namespace = null;
} else {
// Get all the names
for (i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === 'string') {
names.push(arguments[i]);
} else {
newConstructor = arguments[i];
break;
}
// No namespace has been given
if (typeof namespace == 'function') {
newConstructor = namespace;
namespace = null;
}
};
if (Array.isArray(newConstructor)) {
names = newConstructor;
newConstructor = _superConstructor;
if (typeof parentConstructor === 'string') {
names = [parentConstructor];
} else if (Array.isArray(parentConstructor)) {
names = parentConstructor;
}
}
// Set the namespace on the constructor if it's given
if (!newConstructor.namespace) {
if (namespace == null && typeof parentConstructor == 'function') {
namespace = parentConstructor.namespace;
}
if (namespace) {
Blast.defineValue(newConstructor, 'namespace', namespace);
}
}
if (Array.isArray(names)) {
// Make sure all super constructors are available first
for (i = 0; i < names.length; i++) {
name = names[i];
if (name.indexOf('.') > -1) {
path = name;
// Split the path
temp = path.split('.');
// The last part is actually the name
name = temp.pop();
// The namespact is what's left over
namespace = temp.join('.');
} else {
path = name;
}
// If one of the classes isn't available, schedule it for later
if (typeof Blast.Globals[names[i]] !== 'function' && typeof Blast.Classes[names[i]] !== 'function') {
Blast.once({type: 'extended', descendant: names[i]}, function whenClassAvailable() {
if (typeof Obj.path(Blast.Classes, path) !== 'function' && typeof Obj.path(Blast.Globals, path) !== 'function') {
Blast.once({type: 'extended', descendant: name, namespace: namespace}, function whenClassAvailable() {

@@ -114,3 +152,3 @@ var oldProto = newConstructor.prototype,

inherits(names, newConstructor);
inherits(names, namespace, newConstructor);

@@ -155,10 +193,12 @@ if (!oldProto.waitingForClass || !oldProto.hasOwnProperty('waitingForClass')) return;

for (i = 0; i < names.length; i++) {
path = names[i];
temp = Obj.path(Blast.Classes, path);
if (typeof Blast.Classes[names[i]] === 'function') {
superConstructor = Blast.Classes[names[i]];
if (typeof temp === 'function') {
superConstructor = temp;
} else {
superConstructor = Blast.Globals[names[i]];
superConstructor = Obj.path(Blast.Globals, path);
}
inherits(newConstructor, superConstructor);
inherits(superConstructor, namespace, newConstructor);
}

@@ -173,13 +213,13 @@

if (superConstructor) {
if (parentConstructor) {
// Add this class to the parent's children property array
if (!superConstructor.children) {
Blast.defineValue(superConstructor, 'children', []);
if (!parentConstructor.children) {
Blast.defineValue(parentConstructor, 'children', []);
}
superConstructor.children.push(newConstructor);
parentConstructor.children.push(newConstructor);
if (superConstructor.staticChain) {
chain = superConstructor.staticChain;
if (parentConstructor.staticChain) {
chain = parentConstructor.staticChain;

@@ -202,3 +242,3 @@ for (key in chain) {

// Set the super value
Blast.defineValue(newConstructor, 'super', superConstructor);
Blast.defineValue(newConstructor, 'super', parentConstructor);

@@ -208,5 +248,5 @@ // In multiple inheritance the current and new prototypes must be used

proto = Object.create(newConstructor.prototype);
Collection.Object.inject(proto, superConstructor.prototype);
Collection.Object.inject(proto, parentConstructor.prototype);
} else {
proto = superConstructor.prototype;
proto = parentConstructor.prototype;
}

@@ -225,9 +265,9 @@

// Get the parent constitutors and execute them
if (superConstructor.constitutors != null) {
Blast.defineValue(newConstructor, 'constitutors', superConstructor.constitutors.slice());
if (parentConstructor.constitutors != null) {
Blast.defineValue(newConstructor, 'constitutors', parentConstructor.constitutors.slice());
// Execute the constitutors once blast has loaded
Blast.loaded(function goConstitutors() {
for (var i = 0; i < superConstructor.constitutors.length; i++) {
superConstructor.constitutors[i].call(newConstructor);
for (var i = 0; i < parentConstructor.constitutors.length; i++) {
parentConstructor.constitutors[i].call(newConstructor);
}

@@ -237,3 +277,3 @@ });

} else {
superConstructor = Function;
parentConstructor = Function;
}

@@ -261,8 +301,31 @@

if (!targetPath) {
// See if we need to set a namespace
if (namespace == null) {
if (parentConstructor.namespace && !newConstructor.namespace) {
namespace = parentConstructor.namespace;
}
}
if (namespace) {
targetPath = namespace + '.' + newConstructor.name;
} else {
targetPath = newConstructor.name;
}
}
// Store the new class in Blast
Blast.Classes[newConstructor.name] = newConstructor;
Obj.setPath(Blast.Classes, targetPath, newConstructor);
if (Blast.emit) {
Blast.nextTick(function() {
Blast.emit({type: 'extended', ancestor: superConstructor.name, descendant: newConstructor.name}, superConstructor, newConstructor, null);
Blast.nextTick(function emitExtension() {
var data = {
type: 'extended',
ancestor: parentConstructor.name,
descendant: newConstructor.name,
namespace: namespace
};
Blast.emit(data, parentConstructor, newConstructor, null);
});

@@ -450,3 +513,3 @@ }

* @since 0.1.4
* @version 0.1.4
* @version 0.2.0
*

@@ -456,7 +519,9 @@ * @param {Function} target Target object/function to use

* @param {Function} _value The value to set
* @param {Boolean} _inherit Let children inherit this (true)
*/
Blast.defineStatic('Function', 'setStatic', function setStatic(target, _key, _value) {
Blast.defineStatic('Function', 'setStatic', function setStatic(target, _key, _value, _inherit) {
var enumerable,
descriptor,
inherit,
target,

@@ -470,2 +535,3 @@ value,

if (typeof _key === 'function') {
inherit = _value,
value = _key;

@@ -476,4 +542,9 @@ keys = Collection.Array.cast(value.name || undefined);

value = _value;
inherit = _inherit;
}
if (inherit == null) {
inherit = true;
}
if (keys.length === 0 || !keys[0]) {

@@ -483,6 +554,10 @@ throw new Error('Static property must be set to a valid key');

descriptor = {value: value, enumerable: enumerable};
descriptor = {
value: value,
enumerable: enumerable,
configurable: true
};
for (i = 0; i < keys.length; i++) {
addToStaticChain(target, keys[i], descriptor);
if (inherit) addToStaticChain(target, keys[i], descriptor);
Object.defineProperty(target, keys[i], descriptor);

@@ -503,7 +578,9 @@ }

* @param {Function} _setter Function that sets the value
* @param {Boolean} _inherit Let children inherit this (true)
*/
Blast.defineStatic('Function', 'setStaticProperty', function setStaticProperty(target, _key, _getter, _setter) {
Blast.defineStatic('Function', 'setStaticProperty', function setStaticProperty(target, _key, _getter, _setter, _inherit) {
var enumerable,
existing,
inherit,
getter,

@@ -519,2 +596,3 @@ setter,

if (typeof _key === 'function') {
inherit = _setter;
setter = _getter;

@@ -524,2 +602,3 @@ getter = _key;

} else {
inherit = _inherit;
setter = _setter;

@@ -534,2 +613,12 @@ getter = _getter;

if (typeof setter == 'boolean') {
inherit = setter;
setter = null;
}
// Inherit defaults to true
if (inherit == null) {
inherit = true;
}
if (typeof getter == 'function') {

@@ -539,3 +628,4 @@ config = {

set: setter,
enumerable: enumerable
enumerable: enumerable,
configurable: true
};

@@ -545,3 +635,4 @@ } else {

value: getter,
enumerable: enumerable
enumerable: enumerable,
configurable: true
};

@@ -551,3 +642,3 @@ }

for (i = 0; i < keys.length; i++) {
addToStaticChain(target, keys[i], config);
if (inherit) addToStaticChain(target, keys[i], config);
Object.defineProperty(target, keys[i], config);

@@ -843,3 +934,3 @@ }

* @since 0.1.3
* @version 0.1.3
* @version 0.2.0
*

@@ -851,3 +942,3 @@ * @param {Function} newConstructor

var protoExtend = function extend(newConstructor) {
return Fn.inherits(newConstructor, this);
return Fn.inherits(this, newConstructor);
};

@@ -862,9 +953,10 @@

* @since 0.1.4
* @version 0.1.4
* @version 0.2.0
*
* @param {String} key Name to use (defaults to method name)
* @param {Function} value The value to set
* @param {Boolean} inherit Let children inherit this (true)
*/
var protoSetStatic = function setStatic(key, value) {
return Fn.setStatic(this, key, value);
var protoSetStatic = function setStatic(key, value, inherit) {
return Fn.setStatic(this, key, value, inherit);
};

@@ -882,5 +974,6 @@

* @param {Function} setter Function that sets the value
* @param {Boolean} inherit Let children inherit this (true)
*/
var protoSetStaticProperty = function setStaticProperty(key, getter, setter) {
return Fn.setStaticProperty(this, key, getter, setter);
var protoSetStaticProperty = function setStaticProperty(key, getter, setter, inherit) {
return Fn.setStaticProperty(this, key, getter, setter, inherit);
};

@@ -887,0 +980,0 @@

@@ -78,2 +78,3 @@ module.exports = function BlastInit(modifyPrototype) {

'Function',
'Object',
'Array',

@@ -85,2 +86,3 @@ 'Boolean',

'Informer',
'Request',
'FunctionQueue',

@@ -93,3 +95,2 @@ 'Iterator',

'Number',
'Object',
'RegExp',

@@ -650,2 +651,22 @@ 'String',

/**
* Force Protoblast into executing the whenLoaded functions
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 0.2.0
*/
Blast.doLoaded = function doLoaded() {
if (!whenLoaded) {
return;
}
for (var i = 0; i < whenLoaded.length; i++) {
whenLoaded[i]();
}
whenLoaded = false;
};
// Load the inheritance methods

@@ -655,3 +676,3 @@ require('./function_inheritance.js')(Blast, Collection);

// Require the scripts
Names.forEach(function(name) {
Names.forEach(function eachName(name) {
name = name.toLowerCase();

@@ -711,8 +732,3 @@ require('./' + name + '.js')(Blast, Collection);

Blast.setImmediate(function afterOtherScripts() {
for (var i = 0; i < whenLoaded.length; i++) {
whenLoaded[i]();
}
whenLoaded = false;
Blast.doLoaded();
Blast.emit('loaded');

@@ -719,0 +735,0 @@ });

@@ -96,3 +96,3 @@ /**

* @since 0.1.4
* @version 0.1.10
* @version 0.2.0
*

@@ -240,3 +240,17 @@ * @return {Function}

} else if (typeof value.toDry === 'function') {
temp = value;
value = value.toDry();
// If no path was supplied in the toDry,
// get some more class information
if (!value.path) {
if (temp.constructor) {
if (temp.constructor.namespace) {
value.namespace = temp.constructor.namespace;
}
value.dry_class = temp.constructor.name;
}
}
value.dry = 'toDry';

@@ -337,3 +351,3 @@ value.drypath = path.slice(0);

* @since 0.1.4
* @version 0.1.10
* @version 0.2.0
*

@@ -373,4 +387,17 @@ * @return {Function}

case 'toDry':
constructor = Collection.Object.path(Blast.Globals, value.path);
if (value.path) {
constructor = Collection.Object.path(Blast.Globals, value.path);
} else {
if (value.namespace) {
constructor = Collection.Object.path(Blast.Classes, value.namespace);
} else {
constructor = Blast.Classes;
}
if (value.dry_class) {
constructor = Collection.Object.path(constructor, value.dry_class);
}
}
// Undry this element, but don't put it in the parsed object yet

@@ -560,5 +587,6 @@ if (constructor && typeof constructor.unDry === 'function') {

* @since 0.1.6
* @version 0.1.11
* @version 0.2.0
*
* @param {Object} obj
* @param {String} custom_method Custom method to use if available
* @param {WeakMap} wm

@@ -568,3 +596,3 @@ *

*/
Blast.defineStatic('JSON', 'clone', function clone(obj, wm) {
Blast.defineStatic('JSON', 'clone', function clone(obj, custom_method, wm) {

@@ -582,3 +610,3 @@ var nameType,

wm = new WeakMap();
return clone({'_': obj}, wm)['_'];
return clone({'_': obj}, custom_method, wm)['_'];
}

@@ -612,4 +640,6 @@

// Look for a registered drier function first
if (driers[nameType] != null) {
if (custom_method && entry[custom_method]) {
target[keys[i]] = entry[custom_method](wm);
} else if (driers[nameType] != null) {
// Look for a registered drier function
temp = driers[nameType].fnc(obj, keys[i], entry);

@@ -622,2 +652,5 @@

}
} else if (entry.dryClone) {
// Look for dryClone after
target[keys[i]] = entry.dryClone(wm, custom_method);
} else if (entry.toDry) {

@@ -629,3 +662,3 @@ // Perform the toDry function

// because returned objects aren't necesarilly cloned yet
temp = clone(temp.value, wm);
temp = clone(temp.value, custom_method, wm);

@@ -650,2 +683,5 @@ // Perform the undry function

}
} else if (typeof entry.clone == 'function') {
// If it supplies a clone method, use that
target[keys[i]] = entry.clone();
} else if (entry.toJSON) {

@@ -655,3 +691,3 @@ temp = entry.toJSON();

if (temp && typeof temp == 'object') {
temp = clone(temp, wm);
temp = clone(temp, custom_method, wm);
}

@@ -661,6 +697,6 @@

} else {
target[keys[i]] = clone(entry, wm);
target[keys[i]] = clone(entry, custom_method, wm);
}
} else {
target[keys[i]] = clone(entry, wm);
target[keys[i]] = clone(entry, custom_method, wm);
}

@@ -765,2 +801,19 @@

/**
* Safe JSON parsing
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 0.2.0
*
* @return {Mixed}
*/
Blast.defineStatic('JSON', 'safeParse', function safeParse(text, reviver) {
try {
return JSON.parse(text, reviver);
} catch (err) {
return null;
}
});
};

@@ -117,4 +117,5 @@ module.exports = function BlastPath(Blast, Collection) {

* @author Stefan Goessner <goessner.net>
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.0
* @version 0.1.0
* @version 0.2.0
*

@@ -144,10 +145,10 @@ * @return {Array}

if (val && val.hasOwnProperty(loc)) // simple case, directly follow property
addRet(this.trace(x, val[loc], push(path, loc)));
addRet(that.trace(x, val[loc], push(path, loc)));
else if (loc === "*") { // any property
this.walk(loc, x, val, path, function(m,l,x,v,p) {
addRet(this.trace(unshift(m, x), v, p)); });
that.walk(loc, x, val, path, function(m,l,x,v,p) {
addRet(that.trace(unshift(m, x), v, p)); });
}
else if (loc === "..") { // all chid properties
addRet(this.trace(x, val, path));
this.walk(loc, x, val, path, function(m,l,x,v,p) {
addRet(that.trace(x, val, path));
that.walk(loc, x, val, path, function(m,l,x,v,p) {
if (typeof v[m] === "object")

@@ -158,7 +159,7 @@ addRet(that.trace(unshift("..", x), v[m], push(p, m)));

else if (loc[0] === '(') { // [(expr)]
addRet(this.trace(unshift(this.eval(loc, val, path[path.length], path),x), val, path));
addRet(that.trace(unshift(that.eval(loc, val, path[path.length], path),x), val, path));
}
else if (loc.indexOf('?(') === 0) { // [?(expr)]
this.walk(loc, x, val, path, function(m,l,x,v,p) {
if (this.eval(l.replace(/^\?\((.*?)\)$/,"$1"),v[m],m, path))
that.walk(loc, x, val, path, function(m,l,x,v,p) {
if (that.eval(l.replace(/^\?\((.*?)\)$/,"$1"),v[m],m, path))
addRet(that.trace(unshift(m,x),v,p));

@@ -169,6 +170,6 @@ });

for (var parts = loc.split(','), i = 0; i < parts.length; i++)
addRet(this.trace(unshift(parts[i], x), val, path));
addRet(that.trace(unshift(parts[i], x), val, path));
}
else if (/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(loc)) { // [start:end:step] python slice syntax
addRet(this.slice(loc, x, val, path));
addRet(that.slice(loc, x, val, path));
}

@@ -185,3 +186,3 @@

if (ea.isParentSelector) {
result.push(this.trace(ea.expr, val, ea.path));
result.push(that.trace(ea.expr, val, ea.path));
} else {

@@ -188,0 +189,0 @@ result.push(ea);

@@ -66,2 +66,41 @@ module.exports = function BlastObject(Blast, Collection) {

/**
* Get the property descriptor of the given object,
* follow the prototype chain if not found
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 0.2.0
*
* @param {Object} target
* @param {String} key
*
* @return {Object}
*/
Blast.defineStatic('Object', 'getPropertyDescriptor', function getPropertyDescriptor(target, key) {
var proto,
config;
// Get the descriptor
config = Object.getOwnPropertyDescriptor(target, key);
if (config) {
return config;
}
// Config wasn't found, look up the prototype chain
if (typeof target == 'function') {
proto = target.prototype;
} else {
proto = Object.getPrototypeOf(target);
}
if (proto) {
return getPropertyDescriptor(proto, key);
}
return;
});
/**
* Check if the argument is actually an object

@@ -742,3 +781,3 @@ *

* @since 0.1.9
* @version 0.1.11
* @version 0.2.0
*

@@ -782,3 +821,3 @@ * @param {Object} target The object to inject the extension into

} else {
target[key] = Object.assign({}, extension[key]);
target[key] = Collection.Object.assign({}, extension[key]);
}

@@ -789,3 +828,8 @@ } else {

} else {
merge(target[key], extension[key]);
if (target[key] && typeof target[key] == 'object') {
merge(target[key], extension[key]);
} else {
target[key] = Collection.Object.assign(extension[key]);
}
}

@@ -887,3 +931,3 @@ }

* @since 0.1.6
* @version 0.1.6
* @version 0.2.0
*

@@ -895,3 +939,4 @@ * @param {Object} obj

var key;
var key,
ret;

@@ -909,4 +954,10 @@ if (!seen) {

// Fire the function
fnc(obj[key], key, obj);
ret = fnc(obj[key], key, obj);
// If explicit false is returned,
// don't recursively walk this object
if (ret === false) {
continue;
}
if (typeof obj[key] == 'object' && obj[key] !== null) {

@@ -1090,3 +1141,3 @@

* @since 0.1.3
* @version 0.1.11
* @version 0.2.0
*

@@ -1118,3 +1169,3 @@ * @param {Object|Array} obj

// Make sure primitives are primitive
if (type == 'object') {
if (type == 'object' && obj != null) {

@@ -1121,0 +1172,0 @@ // Get the value of the object

@@ -1114,11 +1114,13 @@ module.exports = function BlastString(Blast, Collection) {

* @since 0.0.1
* @version 0.1.2
* @version 0.2.0
*
* @param {Object} values
* @param {Boolean} remove_used Remove used entries from values object
*
* @return {String}
*/
Blast.definePrototype('String', 'fillPlaceholders', function fillPlaceholders(values) {
Blast.definePrototype('String', 'fillPlaceholders', function fillPlaceholders(values, remove_used) {
var result = ''+this,
do_remove,
params,

@@ -1132,2 +1134,6 @@ value,

if (remove_used) {
do_remove = [];
}
if (values && typeof values == 'object') {

@@ -1139,3 +1145,2 @@ params = Blast.Bound.String.placeholders(this);

regex = new RegExp('(:' + params[i] + ')(?:\\W|$)', 'g');
value = Blast.Bound.Object.path(values, params[i]);

@@ -1145,2 +1150,6 @@

if (remove_used) {
do_remove.push(params[i]);
}
while (match = regex.exec(result)) {

@@ -1161,2 +1170,8 @@

if (remove_used) {
for (i = 0; i < do_remove.length; i++) {
delete values[do_remove[i]];
}
}
return result;

@@ -1163,0 +1178,0 @@ });

{
"name": "protoblast",
"description": "Add useful methods to native objects",
"version": "0.1.12",
"version": "0.2.0",
"author": "Jelle De Loecker <jelle@develry.be>",

@@ -6,0 +6,0 @@ "keywords": [

@@ -65,3 +65,3 @@ var assert = require('assert'),

it('should format the date using the specified methos', function() {
it('should format the date using the specified methods', function() {

@@ -130,9 +130,9 @@ var a = new Date(date),

//assert.equal(e.format('I'), false, 'DST should be false');
assert.equal(e.format('O'), '+0100', 'Difference to GMT');
assert.equal(e.format('P'), '+01:00', 'Difference to GMT with colon');
//assert.equal(e.format('O'), '+0100', 'Difference to GMT');
//assert.equal(e.format('P'), '+01:00', 'Difference to GMT with colon');
// Date/Time
assert.equal(a.format('c'), '2015-08-26T16:39:05+02:00');
assert.equal(a.format('r'), 'Wed Aug 26 2015 16:39:05 GMT+0200 (CEST)');
assert.equal(e.format('U'), '1453790345.745');
//assert.equal(a.format('c'), '2015-08-26T16:39:05+02:00');
//assert.equal(a.format('r'), 'Wed Aug 26 2015 16:39:05 GMT+0200 (CEST)');
//assert.equal(e.format('U'), '1453790345.745');
});

@@ -139,0 +139,0 @@

@@ -18,3 +18,3 @@ var assert = require('assert'),

describe('.Median(numbers)', function() {
describe('.median(numbers)', function() {

@@ -33,6 +33,27 @@ it('should return the median value of the numbers without changing the original array', function() {

assert.equal(post, pre, 'The original array was modified');
});
it('should use the arguments', function() {
assert.equal(Math.median(4, 9, 3), 4);
assert.equal(Math.median(1, 2, 4, 9), 3);
});
});
describe('.mean(numbers)', function() {
it('should return the mean value of the numbers', function() {
var numbers = originalNumbers.slice(0),
result;
result = Math.mean([1, 4, 10]);
assert.equal(result, 5, 'The mean value should be 5');
});
it('should use the arguments', function() {
assert.equal(Math.mean(1, 4, 10), 5);
});
});
describe('.lowest(numbers, amount)', function() {

@@ -87,4 +108,8 @@

assert.equal(sum, 15);
assert.equal(15, sum);
});
it('should sum up all the given arguments', function() {
assert.equal(15, Math.sum(1, 2, 3, 4, 5));
});
});

@@ -91,0 +116,0 @@

@@ -15,3 +15,4 @@ var assert = require('assert'),

dec = Number.random(0,10),
neg = Number.random(-10,0);
neg = Number.random(-10,0),
max = Number.random(1000);

@@ -26,2 +27,5 @@ assert.equal(true, def > -1, 'Default should return an integer above -1');

assert.equal(true, neg < 1, '(0,10) should return an integer under 1');
assert.equal(true, max > -1, '(1000) should return an integer above -1');
assert.equal(true, max < 1001, '(1000) should return an integer under 1001');
});

@@ -91,2 +95,25 @@ });

describe('#toByte(to)', function() {
it('should interpret the number as bytes and convert to another byte factor', function() {
var KiB = 1024,
GiB = 1073741824;
assert.equal(1, KiB.toByte('kib'), '1024 should be 1 kib');
assert.equal(1, GiB.toByte('gib'), 'Should be 1 gib');
assert.equal(1.1, GiB.toByte('gb'), 'Should be 1.1 gb (not gib)');
});
});
describe('#toByte(from, to)', function() {
it('should interpret the number as given byte factor and convert to another factor', function() {
var a = 1024,
b = 1073741824;
assert.equal(1, a.toByte('b', 'kib'), '1024 should be 1 kib');
assert.equal(1, a.toByte('gib', 'tib'), '1024 gib should be 1 tib');
assert.equal(1, a.toByte('gb', 'tb'));
assert.equal(1024, 1024..toByte(1, 1), 'When to is not a string, default to bytes');
});
});
});

@@ -26,2 +26,42 @@ var assert = require('assert'),

describe('.getPropertyDescriptor(target, key)', function() {
var TestClass,
descriptor,
own;
// Create the test class
TestClass = function TestClass() {};
// Create the descriptor
descriptor = {
value: function testMethod() {}
};
// Set some properties
Object.defineProperty(TestClass.prototype, 'testMethod', descriptor);
// Get the property descriptor using the native method
own = Object.getOwnPropertyDescriptor(TestClass.prototype, 'testMethod');
it('should return the wanted property descriptor, like native method', function() {
var desc = Object.getPropertyDescriptor(TestClass.prototype, 'testMethod');
assert.equal(own.value, desc.value);
});
it('should look for the descriptor in the prototype property if a function is given', function() {
var desc = Object.getPropertyDescriptor(TestClass, 'testMethod');
assert.equal(own.value, desc.value);
});
it('should look even further up the chain until it finds something', function() {
var desc,
obj = new TestClass();
desc = Object.getPropertyDescriptor(obj, 'testMethod');
assert.equal(own.value, desc.value);
});
});
describe('.isObject(obj)', function() {

@@ -399,2 +439,17 @@ it('should return true for regular objects', function() {

describe('.first()', function() {
it('should return the first value it sees in the object', function() {
assert.equal(47, Object.first({a: 47}));
});
it('should return index 0 of an array', function() {
assert.equal(55, Object.first([55, 23]));
});
it('should return the object itself if it is empty', function() {
var a = {};
assert.equal(a, Object.first(a));
})
});
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc