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.10 to 0.1.11-alpha

24

CHANGELOG.md

@@ -0,1 +1,25 @@

## 0.1.11 (2016-01-08)
* `String#slug` now removes diacritics and separator repeats
* Improve `Object.merge`, still not ready for release though
* Add `getChildren` method to class functions
* Make class constitutions happen in order
(child constitution would happen before the parent's)
* Don't use broken URLConstructor objects on legacy browsers
* `Array#include` now appends when no index is given
* `Date.create` now accepts a value
* `Date.difference` now uses `Date.create` instead of `new Date`
* `Array#include` correctly handles single argument
* Added `Object.first`
* Use `#valueOf()` when getting object checksums,
fixes `Date` instances getting the same checksums
* Add `String#fixHTML` and `String#truncateHTML`
* Fix JSON-dry special char bug
* Decode HTML when slugifying a string
* Improve `Object.setPath`
* Add `Object.formPath` and `Object.setFormPath`
* `JSON.clone` is now much more performant than the old method
* Properties set on a Deck instance now also get JSON-dried
* Fix pushed tasks in `Function.hinder` object
## 0.1.10 (2015-08-27)

@@ -2,0 +26,0 @@

21

lib/array.js

@@ -507,3 +507,3 @@ module.exports = function BlastArray(Blast, Collection) {

* @since 0.1.4
* @version 0.1.4
* @version 0.1.11
*

@@ -515,7 +515,16 @@ * @param {Number} index Where to insert the contents of the array

*/
Blast.definePrototype('Array', 'include', function include(index, values) {
Blast.definePrototype('Array', 'include', function include(_index, values) {
var allValues,
index,
i;
if (arguments.length == 1 || _index == null || typeof _index != 'number') {
index = this.length;
i = 1;
} else {
index = _index;
i = 2;
}
if (this.length < index-1) {

@@ -526,10 +535,10 @@ this.length = index;

// Start with all the values of the first array
if (Array.isArray(arguments[1])) {
allValues = arguments[1].slice();
if (Array.isArray(arguments[i-1])) {
allValues = arguments[i-1].slice();
} else {
allValues = [arguments[1]];
allValues = [arguments[i-1]];
}
// Now add all the other arrays
for (i = 2; i < arguments.length; i++) {
for (; i < arguments.length; i++) {
allValues = allValues.concat(arguments[i]);

@@ -536,0 +545,0 @@ }

@@ -145,3 +145,3 @@ module.exports = function BlastCrypto(Blast, Collection) {

* @since 0.1.4
* @version 0.1.4
* @version 0.1.11
*

@@ -158,3 +158,3 @@ * @param {Number} bytesize

if (callback == null) {
return Crypto.randomBytes().toString('hex');
return Crypto.randomBytes(bytesize).toString('hex');
}

@@ -161,0 +161,0 @@

@@ -23,6 +23,10 @@ module.exports = function BlastDate(Blast, Collection) {

* @since 0.1.0
* @version 0.1.0
* @version 0.1.11
*/
Blast.defineStatic('Date', 'create', function create() {
return new Date();
Blast.defineStatic('Date', 'create', function create(value) {
if (value == null) {
return new Date();
} else {
return new Date(value);
}
});

@@ -46,3 +50,3 @@

* @since 0.1.8
* @version 0.1.8
* @version 0.1.11
*

@@ -66,4 +70,4 @@ * @param {String} unit year, quarter, month, week, day, ...

start = new Date(start);
end = new Date(end);
start = Collection.Date.create(start);
end = Collection.Date.create(end);

@@ -70,0 +74,0 @@ if (unit != null) {

@@ -78,3 +78,3 @@ module.exports = function BlastDeck(Blast, Collection) {

* @since 0.1.4
* @version 0.1.4
* @version 0.1.11
*

@@ -85,3 +85,4 @@ * @return {Object}

var result = new Deck();
var result = new Deck(),
key;

@@ -93,2 +94,6 @@ result.dict = obj.dict;

for (key in obj.attributes) {
result[key] = obj.attributes[key];
}
return result;

@@ -123,3 +128,3 @@ });

* @since 0.1.4
* @version 0.1.4
* @version 0.1.11
*

@@ -129,2 +134,26 @@ * @return {Object}

Deck.setMethod('toDry', function toDry() {
var attributes = {},
keys = Object.keys(this),
key,
i;
for (i = 0; i < keys.length; i++) {
key = keys[i];
switch (key) {
case 'dict':
case 'array':
case '_iterSubject':
case 'insertCount':
case 'sorted':
case 'sortedItems':
case '_iterSubjectIsArray':
continue;
default:
attributes[key] = this[key];
}
}
return {

@@ -134,3 +163,4 @@ value: {

dict: this.dict,
array: this.array
array: this.array,
attributes: attributes
},

@@ -298,2 +328,44 @@ path: '__Protoblast.Classes.Deck'

/**
* Find inside value
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @param {Mixed} key_value
* @param {Boolean} recursive Look through other decks? [true]
*
* @return {Mixed}
*/
Deck.setMethod(function findByKey(key_value, recursive) {
var result,
entry,
val,
i;
if (recursive == null) {
recursive = true;
}
// Go over entry in this deck
for (i = 0; i < this.array.length; i++) {
entry = this.array[i];
val = entry.value;
if (entry.key === key_value) {
return val;
}
// Only look in objects
if (val && typeof val == 'object') {
if (val.constructor && val.constructor.name == 'Deck') {
result = val.findByKey(key_value, recursive);
if (result) return result;
}
}
}
});
/**
* Get the sorted values

@@ -300,0 +372,0 @@ *

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

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

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

var i;
if (err != null) {

@@ -737,7 +739,4 @@ throw err;

// Start executing the tasks waiting
if (tasks.length) {
Collection.Function.parallel(forceAsync, tasks, function afterTasks(err) {
throw err;
});
for (i = 0; i < tasks.length; i++) {
tasks[i]();
}

@@ -744,0 +743,0 @@ };

@@ -64,3 +64,3 @@ module.exports = function BlastInheritance(Blast, Collection) {

* @since 0.1.3
* @version 0.1.9
* @version 0.1.11
*

@@ -222,5 +222,8 @@ * @param {Function} newConstructor

for (i = 0; i < newConstructor.constitutors.length; i++) {
newConstructor.constitutors[i].call(newConstructor);
}
// 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);
}
});
}

@@ -239,2 +242,3 @@ } else {

Blast.defineValue(newConstructor, 'staticCompose', protoStaticCompose);
Blast.defineValue(newConstructor, 'getChildren', protoGetChildren);
Blast.defineValue(newConstructor, 'setProperty', protoSetProperty);

@@ -787,2 +791,31 @@ Blast.defineValue(newConstructor, 'constitute', protoConstitute);

/**
* Get all the children of a certain class
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @return {Array}
*/
Blast.defineStatic('Function', 'getChildren', function getChildren(constructor) {
var result = [];
if (constructor.children) {
// Iterate over all the children
constructor.children.forEach(function eachChild(child) {
result.push(child);
// Recursively iterate over the children's children
if (child.children && child.children.length) {
child.children.forEach(eachChild);
}
});
}
return result;
});
/**
* Inherit from the function

@@ -937,2 +970,15 @@ *

/**
* Get all the children of a certain class
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @return {Array}
*/
var protoGetChildren = function getChildren() {
return Fn.getChildren(this);
};
Blast.definePrototype('Function', 'prepareStaticProperty', protoPrepareStaticProperty);

@@ -942,2 +988,3 @@ Blast.definePrototype('Function', 'setStaticProperty', protoSetStaticProperty);

Blast.definePrototype('Function', 'staticCompose', protoStaticCompose);
Blast.definePrototype('Function', 'getChildren', protoGetChildren);
Blast.definePrototype('Function', 'setProperty', protoSetProperty);

@@ -944,0 +991,0 @@ Blast.definePrototype('Function', 'constitute', protoConstitute);

@@ -913,3 +913,5 @@ module.exports = function BlastInformer(Blast, Collection) {

// Throw the error when no callback is given
if (err) throw err;
if (err) Blast.setImmediate(function throwError() {
throw err;
});

@@ -916,0 +918,0 @@ return;

@@ -130,2 +130,3 @@ /**

temp,
last,
len,

@@ -149,2 +150,7 @@ i,

holder.__isWrap = true;
// See if the wrapped value is an object
if (holder[''] && typeof holder[''] === 'object') {
holder.__isObject = true;
}
}

@@ -181,6 +187,8 @@

if (!isWrap && holder !== chain[len-1]) {
temp = chain.pop();
last = chain.pop();
// Only pop the path if the popped object isn't a wrapper
if (temp && !temp.__isWrap) {
// @todo: also check for __isObject or not?
if (last && !last.__isWrap) {
path.pop();

@@ -254,5 +262,11 @@ }

// that return primitive values
chain.pop();
path.pop();
temp = chain.pop();
// Don't pop off anything from the path if the last item
// from the chain was a wrapper for an object,
// because then it'll already be popped of
if (!(temp && temp.__isWrap && temp.__isObject)) {
temp = path.pop();
}
break;

@@ -292,3 +306,3 @@ }

value = value.replace(safeSpecialCharRG, escapedSafeSpecialChar)
.replace(specialCharRG, safeSpecialChar);
.replace(specialChar, safeSpecialChar);
}

@@ -543,14 +557,113 @@

/**
* Clone an object using regular JSON
* Deep clone an object
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.6
* @version 0.1.6
* @version 0.1.11
*
* @param {Object} obj
* @param {WeakMap} wm
*
* @return {Object}
*/
Blast.defineStatic('JSON', 'clone', function clone(obj) {
return JSON.parse(JSON.stringify(obj));
Blast.defineStatic('JSON', 'clone', function clone(obj, wm) {
var nameType,
entry,
split,
keys,
temp,
len,
i,
target;
if (wm == null) {
wm = new WeakMap();
return clone({'_': obj}, wm)['_'];
}
if (Array.isArray(obj)) {
target = [];
} else {
target = {};
}
keys = Object.keys(obj);
len = keys.length;
// Remember the root object and its clone
wm.set(obj, target);
for (i = 0; i < len; i++) {
entry = obj[keys[i]];
if (entry && typeof entry == 'object') {
// If this has been cloned before, use that
if (wm.has(entry)) {
target[keys[i]] = wm.get(entry);
continue;
}
if (entry.constructor) {
nameType = entry.constructor.name;
// Look for a registered drier function first
if (driers[nameType] != null) {
temp = driers[nameType].fnc(obj, keys[i], entry);
if (undriers[nameType]) {
target[keys[i]] = undriers[nameType].fnc(target, keys[i], temp);
} else {
target[keys[i]] = temp;
}
} else if (entry.toDry) {
// Perform the toDry function
temp = entry.toDry();
// Clone the value,
// because returned objects aren't necesarilly cloned yet
temp = clone(temp.value, wm);
// Perform the undry function
if (entry.constructor.unDry) {
target[keys[i]] = entry.constructor.unDry(temp);
} else {
// If there is no undry function, the clone will be a simple object
target[keys[i]] = temp;
}
} else if (nameType == 'Date') {
target[keys[i]] = new Date(entry);
} else if (nameType == 'RegExp') {
temp = entry.toString();
split = temp.match(/^\/(.*?)\/([gim]*)$/);
if (split) {
target[keys[i]] = new RegExp(split[1], split[2]);
} else {
target[keys[i]] = new RegExp(temp);
}
} else if (entry.toJSON) {
temp = entry.toJSON();
if (temp && typeof temp == 'object') {
temp = clone(temp, wm);
}
target[keys[i]] = temp;
} else {
target[keys[i]] = clone(entry, wm);
}
} else {
target[keys[i]] = clone(entry, wm);
}
// Remember this clone for later
wm.set(entry, target[keys[i]]);
} else {
target[keys[i]] = entry;
}
}
return target;
});

@@ -557,0 +670,0 @@

@@ -378,3 +378,3 @@ module.exports = function BlastObject(Blast, Collection) {

* @since 0.1.4
* @version 0.1.9
* @version 0.1.11
*/

@@ -413,2 +413,6 @@ Blast.defineStatic('Object', 'setPath', function setPath(obj, path, value, skipLastEntry) {

if (key == '') {
key = here.length;
}
// Is this the final piece?

@@ -426,3 +430,3 @@ end = ((i+1) == pieces.length);

// AND the next key is a number, create an array
if (Number(pieces[i+1]) == pieces[i+1]) {
if (pieces[i+1] === '' || Number(pieces[i+1]) == pieces[i+1]) {
here[key] = [];

@@ -440,3 +444,62 @@ } else {

/**
* Extract form path info
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @param {String} str
*/
function getFormPathArray(str) {
var root_name = /^(.*?)(?:\[|$)/,
prop_name = /(?:\[(.*?)\])/g,
properties = [],
temp;
temp = root_name.exec(str);
// Look for the root name
if (temp && typeof temp[1] !== 'undefined') {
properties.push(temp[1]);
}
// Look for the sub property names
while (temp = prop_name.exec(str)) {
properties.push(temp[1]);
}
return properties;
}
/**
* Get the value of the given property path (in the form format)
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @param {Object} obj
* @param {String} form_path The form notation path
*/
Blast.defineStatic('Object', 'formPath', function formPath(obj, form_path) {
var path = getFormPathArray(form_path);
return Collection.Object.path(obj, path);
});
/**
* Create a path in an object.
* Example: my[special][object] would create an object like
* {my: {special: {object: {}}}}
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*/
Blast.defineStatic('Object', 'setFormPath', function setFormPath(obj, form_path, value, skipLastEntry) {
var path = getFormPathArray(form_path);
return Collection.Object.setPath(obj, path, value, skipLastEntry);
});
/**
* See if the given path exists inside an object,

@@ -682,3 +745,3 @@ * even if that value is undefined

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

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

var length = arguments.length, extension, key, i;
var length = arguments.length, extension, key, i, j;

@@ -701,9 +764,32 @@ // Go over every argument, other than the first

if (!extension) continue;
if (Array.isArray(extension)) {
if (!Array.isArray(target)) {
target = [];
}
for (j = 0; j < extension.length; j++) {
target.push(extension[j]);
}
continue;
}
// Go over every property of the current object
for (key in extension) {
if (!target[key]) {
target[key] = extension[key];
if (!extension[key] || typeof extension[key] != 'object') {
// Null or primitives
target[key] = extension[key];
} else if (Array.isArray(extension[key])) {
target[key] = extension[key].slice(0);
} else {
target[key] = Object.assign({}, extension[key]);
}
} else {
merge(target[key], extension[key]);
if (!extension[key] || typeof extension[key] != 'object') {
target[key] = extension[key];
} else {
merge(target[key], extension[key]);
}
}

@@ -1004,3 +1090,3 @@ }

* @since 0.1.3
* @version 0.1.10
* @version 0.1.11
*

@@ -1032,5 +1118,13 @@ * @param {Object|Array} obj

// Make sure primitives are primitive
if (type == 'object' && Blast.Bound.Object.isPrimitiveObject(obj)) {
obj = obj.valueOf();
type = typeof obj;
if (type == 'object') {
// Get the value of the object
temp = obj.valueOf();
// If the value is different, use that from here on out
// This handles primitive objects & dates
if (temp != obj) {
obj = temp;
type = typeof obj;
}
}

@@ -1211,2 +1305,27 @@

/**
* Get the first entry of an object or array
* If it is neither, just return the value
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @param {Object} obj
*/
Blast.defineStatic('Object', 'first', function first(obj) {
var key;
if (Array.isArray(obj)) {
return obj[0];
} else if (obj && typeof obj == 'object') {
for (key in obj) {
return obj[key];
}
}
return obj;
});
};

@@ -498,3 +498,3 @@ module.exports = function BlastString(Blast, Collection) {

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

@@ -512,3 +512,9 @@ * @return {String} The sluggifier string

result = this.toLowerCase();
// Romanize the string (remove diacritics)
result = Blast.Bound.String.romanize(result);
// Decode HTML
result = Blast.Bound.String.decodeHTML(result);
// Replace non-words with placeholders

@@ -520,2 +526,5 @@ result = result.replace(/[^\w ]+/g, '=');

// Truncate repeats of the separator
result = result.replace(Blast.Bound.RegExp.interpret('/\\' + separator + '+/g'), separator);
// Make sure the first char isn't the separator

@@ -657,2 +666,99 @@ if (result[0] == separator) {

/**
* Truncate an HTML string
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @param {Number} length The maximum length of the string
* @param {Boolean} word Cut off at a word border
* @param {String} ellipsis How to indicate it's been cut
*
* @return {String} The truncated string
*/
Blast.definePrototype('String', 'truncateHTML', function truncateHTML(length, word, ellipsis) {
var tag_length = 0,
temp,
i;
// Extract all the tags from the input string
temp = this.substr(0, length).match(/<(\/?)(.*?)>/g);
// Get the sum of the length of all the tags
for (i = 0; i < temp.length; i++) {
tag_length += temp[i].length;
}
// Truncate the input string
temp = Blast.Bound.String.truncate(this, length + tag_length, word, ellipsis);
// Now fix the html
return Blast.Bound.String.fixHTML(temp);
});
/**
* Close open HTML tags
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.11
* @version 0.1.11
*
* @return {String} The fixed HTML
*/
Blast.definePrototype('String', 'fixHTML', function fixHTML() {
var open_tags,
tag_name,
output,
input,
regex,
tags,
temp,
tag,
i;
open_tags = [];
input = this;
tags = Blast.Bound.RegExp.execAll(/<(\/?)(.*?)>/ig, input);
for (i = 0; i < tags.length; i++) {
tag = tags[i];
tag_name = tag[2].replace(/\//g, '');
// If it's a close tag ...
if (tag[1]) {
temp = open_tags.lastIndexOf(tag_name);
// See if this actually closes something present
if (temp > -1) {
open_tags.splice(temp, 1);
} else {
// Maybe remove this close tag?
}
} else {
// Ignore self closing tags
switch (tag_name) {
case 'br':
case 'li':
break;
default:
open_tags.push(tag_name);
}
}
}
for (i = 0; i < open_tags.length; i++) {
input += '</' + open_tags[i] + '>';
}
return input;
});
/**
* Replace every occurence of needle in the string without using regexes

@@ -659,0 +765,0 @@ *

@@ -84,2 +84,9 @@ module.exports = function BlastURL(Blast, Collection) {

});
} else if (!Blast.isNode) {
// Detect broken URL constructor objects
if (Object.prototype.toString.call(window.URL) == '[object URLConstructor]') {
Blast.Classes.URL = URL;
Blast.Bound.URL = {};
Blast.Collection.URL = URL;
}
}

@@ -86,0 +93,0 @@

{
"name": "protoblast",
"description": "Add useful methods to native objects",
"version": "0.1.10",
"version": "0.1.11-alpha",
"author": "Jelle De Loecker <jelle@develry.be>",
"keywords": ["prototype", "util", "functional", "server", "client", "browser"],
"main": "./lib/init.js",
"repository": "skerit/protoblast",

@@ -9,0 +8,0 @@ "homepage": "http://protoblast.develry.be/",

@@ -512,2 +512,9 @@ var assert = require('assert'),

});
it('should append when no index is given', function() {
var original = [0,1,2],
result = original.include([3,4], [5,6]);
assert.equal(result+'', '0,1,2,3,4,5,6');
});
});

@@ -514,0 +521,0 @@

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

assert.equal(driedtwo, '{"a":"This is \\\\x7enot\\\\x7e undefined"}', 'Special chars in an object should be escaped');
assert.equal(driedtwo, '{"a":"This is \\\\x7enot~ undefined"}', 'The first special char should be escaped');
assert.equal(dried, JSON.stringify(input), 'Special chars should not be escaped in a regular string');

@@ -223,0 +223,0 @@ assert.equal(undried, input);

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