Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wodge

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wodge - npm Package Compare versions

Comparing version 0.6.1 to 0.6.2

r.js

422

boil.json
{
"readme":{
"template": "[![view on npm](http:\/\/img.shields.io\/npm\/v\/wodge.svg)](https:\/\/www.npmjs.org\/package\/wodge)\n![npm module downloads per month](http:\/\/img.shields.io\/npm\/dm\/wodge.svg)\n[![Dependency Status](https:\/\/david-dm.org\/75lb\/wodge.svg)](https:\/\/david-dm.org\/75lb\/wodge)\n![Analytics](https:\/\/ga-beacon.appspot.com\/UA-27725889-25\/wodge\/README.md?pixel)\n\n[![browser support](https:\/\/ci.testling.com\/75lb\/wodge.png)](https:\/\/ci.testling.com\/75lb\/wodge)\n\n#wodge\nA collection of useful functions.\n\n#API Documentation\nGenerated jsdoc documentation.\n\n{{#if functions}}{{#each functions}}##{{{name}}}\n{{#if description}}{{{description}}}\n\n{{\/if~}}\n\n{{#if parameters}}###Parameters\n{{#each parameters}}{{name}} { {{~type~}} } - {{{description}}}\n{{\/each}}\n{{\/if~}}\n\n{{#if examples}}###Example\n{{#each examples}}```js\n{{{this}}}\n```\n{{\/each}}{{\/if~}}\n\n{{#if returns}}**Returns** {{returns.type}} {{returns.description}}\n\n{{\/if~}}\n\n\n{{\/each}}{{\/if}}",
"template": "[![view on npm](http:\/\/img.shields.io\/npm\/v\/wodge.svg)](https:\/\/www.npmjs.org\/package\/wodge)\n![npm module downloads per month](http:\/\/img.shields.io\/npm\/dm\/wodge.svg)\n[![Dependency Status](https:\/\/david-dm.org\/75lb\/wodge.svg)](https:\/\/david-dm.org\/75lb\/wodge)\n![Analytics](https:\/\/ga-beacon.appspot.com\/UA-27725889-25\/wodge\/README.md?pixel)\n\n[![browser support](https:\/\/ci.testling.com\/75lb\/wodge.png)](https:\/\/ci.testling.com\/75lb\/wodge)\n\n#wodge\nA collection of useful functions.\n\n#API Documentation\nGenerated jsdoc documentation.\n\n{{#if functions}}{{#each functions}}##{{{name}}}\n{{#if description}}{{{description}}}\n\n{{\/if~}}\n\n{{#if parameters}}###Parameters\n{{#each parameters}}{{name}} { {{~type~}} } - {{{description}}}{{#if optional}} *optional*{{\/if}}{{#if default}} *default={{{default}}}*{{\/if}} \n{{\/each}}\n{{\/if~}}\n\n{{#if examples}}###Example\n{{#each examples}}```js\n{{{this}}}\n```\n{{\/each}}{{\/if~}}\n\n{{#if returns}}**Returns** {{returns.type}} {{{returns.description}}}\n\n{{\/if~}}\n\n\n{{\/each}}{{\/if}}",
"data": {

@@ -22,3 +22,3 @@ "functions": [

"examples": [
"w.extend({}, { one: 1, three: 3 }, { one: \"one\", two: 2 }, { four: 4 });\n// { one: \"one\", two: 2, three: 3, four: 4 }"
"> w.extend({}, { one: 1, three: 3 }, { one: \"one\", two: 2 }, { four: 4 });\n{ one: 'one',\n three: 3,\n two: 2,\n four: 4 }"
]

@@ -30,8 +30,11 @@ },

"virtual": false,
"description": "Returns a copy of the input object",
"description": "Clones an object or array",
"parameters": [
{
"name": "input",
"type": "Object",
"description": "the object to clone",
"type": [
"Object",
"Array"
],
"description": "the input to clone",
"default": "",

@@ -42,5 +45,10 @@ "optional": "",

],
"examples": [],
"examples": [
"> date = new Date()\nFri May 09 2014 13:54:34 GMT+0200 (CEST)\n> w.clone(date)\n{} // a Date instance doensn't own any properties\n> date.clive = \"hater\"\n'hater'\n> w.clone(date)\n{ clive: 'hater' }\n> array = [1,2,3]\n[ 1, 2, 3 ]\n> newArray = w.clone(array)\n[ 1, 2, 3 ]\n> array === newArray\nfalse"
],
"returns": {
"type": "Object",
"type": [
"Object",
"Array"
],
"description": ""

@@ -56,3 +64,3 @@ }

{
"name": "input",
"name": "object",
"type": "Object",

@@ -74,3 +82,3 @@ "description": "the object to clone",

"examples": [
"w.omit({ one: 1, two: 2, three: 3, four: 4 }, [ \"two\", \"four\" ]);\n// { one: 1, three: 3 }"
"> w.omit({ one: 1, two: 2, three: 3, four: 4 }, [ \"two\", \"four\" ]);\n{ one: 1, three: 3 }"
],

@@ -89,3 +97,3 @@ "returns": {

"examples": [
"w.escapeRegExp(\"(.*)\"); \n// '\\\\(\\\\.\\\\*\\\\)'"
"> w.escapeRegExp(\"(.*)\");\n'\\\\(\\\\.\\\\*\\\\)'"
]

@@ -117,3 +125,3 @@ },

"examples": [
"var data = [\n {one: 1, two: 2},\n {two: \"two\"},\n {one: \"one\", two: \"zwei\"},\n];\n\nw.pluck(data, \"one\");\n// [ 1, \"one\" ]\n\nw.pluck(data, \"two\");\n// [ 2, \"two\", \"zwei\" ]\n\nw.pluck(data, \"one\", \"two\");\n// [ 1, \"two\", \"one\" ]"
"> var data = [\n... {one: 1, two: 2},\n... {two: \"two\"},\n... {one: \"one\", two: \"zwei\"},\n... ];\nundefined\n> w.pluck(data, \"one\");\n[ 1, 'one' ]\n> w.pluck(data, \"two\");\n[ 2, 'two', 'zwei' ]\n> w.pluck(data, \"one\", \"two\");\n[ 1, 'two', 'one' ]"
],

@@ -126,10 +134,147 @@ "returns": {

{
"name": "arrayify",
"name": "isNumber",
"access": "",
"virtual": false,
"description": "Either:\n\n- puts a single scalar in an array\n- converts array-like object to a real array\n- converts null or undefined to an empty array",
"description": "Returns true if input is a number",
"parameters": [],
"examples": []
"examples": [
"> w.isNumber(0)\ntrue\n> w.isNumber(1)\ntrue\n> w.isNumber(1.1)\ntrue\n> w.isNumber(0xff)\ntrue\n> w.isNumber(0644)\ntrue\n> w.isNumber(6.2e5)\ntrue\n> w.isNumber(a)\nfalse\n> w.isNumber(NaN)\nfalse\n> w.isNumber(Infinity)\nfalse"
]
},
{
"name": "isPlainObject",
"access": "",
"virtual": false,
"description": "Returns true if input type is `object` and not an Array",
"parameters": [
{
"name": "input",
"type": "*",
"description": "the input to test",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> w.isPlainObject(new Date())\ntrue\n> w.isPlainObject({ clive: \"hater\" })\ntrue\n> w.isPlainObject([ 0, 1 ])\nfalse"
],
"returns": {
"type": "boolean",
"description": ""
}
},
{
"name": "arrayify",
"access": "",
"virtual": false,
"description": "Takes input and guarantees an array back. Result can be one of three things:\n\n- puts a single scalar in an array\n- converts array-like object (e.g. `arguments`) to a real array\n- converts null or undefined to an empty array",
"parameters": [
{
"name": "input",
"type": "*",
"description": "the input value to convert to an array",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> w.arrayify(null)\n[]\n> w.arrayify(0)\n[ 0 ]\n> w.arrayify([ 1, 2 ])\n[ 1, 2 ]\n> function f(){ return w.arrayify(arguments); }\nundefined\n> f(1,2,3)\n[ 1, 2, 3 ]"
],
"returns": {
"type": "Array",
"description": ""
}
},
{
"name": "every",
"access": "",
"virtual": false,
"description": "Returns true if the supplied iterator function returns true for every property in the object",
"parameters": [
{
"name": "object",
"type": "Object",
"description": "the object to inspect",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "iterator",
"type": "function",
"description": "the iterator function to run against each key/value pair, the args are `(value, key)`.",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> function aboveTen(input){ return input > 10; }\nundefined\n> w.every({ eggs: 12, carrots: 30, peas: 100 }, aboveTen)\ntrue\n> w.every({ eggs: 6, carrots: 30, peas: 100 }, aboveTen)\nfalse"
],
"returns": {
"type": "Boolean",
"description": ""
}
},
{
"name": "each",
"access": "",
"virtual": false,
"description": "Runs the iterator function against every key/value pair in the input object",
"parameters": [
{
"name": "object",
"type": "Object",
"description": "the object to iterate",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "callback",
"type": "function",
"description": "the iterator function to run against each key/value pair, the args are `(value, key)`.",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> var total = 0;\nundefined\n> function addToTotal(n){ total += n; }\nundefined\n> w.each({ eggs: 3, celery: 2, carrots: 1 }, addToTotal)\nundefined\n> total\n6"
]
},
{
"name": "bytesToSize",
"access": "",
"virtual": false,
"description": "Convert bytes to human-readable size",
"parameters": [
{
"name": "bytes",
"type": "number",
"description": "the bytes value to convert",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "precision",
"type": "number",
"description": "number of decimal places",
"default": "0",
"optional": true,
"nullable": ""
}
],
"examples": [
"> w.bytesToSize(10000)\n'10 KB'\n> w.bytesToSize(10000, 1)\n'9.8 KB'\n> w.bytesToSize(10000, 2)\n'9.77 KB'\n> w.bytesToSize(10000, 3)\n'9.766 KB'"
],
"returns": {
"type": "string",
"description": ""
}
},
{
"name": "getHomeDir",

@@ -140,21 +285,179 @@ "access": "",

"parameters": [],
"examples": []
"examples": [
"> w.getHomeDir()\n'/Users/Lloyd'"
]
},
{
"name": "fill",
"access": "",
"virtual": false,
"description": "Create a new string filled with the supplied character",
"parameters": [
{
"name": "fillWith",
"type": "string",
"description": "the fill character",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "len",
"type": "number",
"description": "the length of the output string",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> w.fill(\"a\", 10)\n'aaaaaaaaaa'\n> w.fill(\"ab\", 10)\n'aaaaaaaaaa'"
],
"returns": {
"type": "string",
"description": ""
}
},
{
"name": "padRight",
"access": "",
"virtual": false,
"description": "Add padding to the right of a string",
"parameters": [
{
"name": "input",
"type": "string",
"description": "the string to pad",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "width",
"type": "number",
"description": "the desired final width",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "padWith",
"type": "string",
"description": "the padding character",
"default": "\" \"",
"optional": true,
"nullable": ""
}
],
"examples": [
"> w.padRight(\"clive\", 1)\n'clive'\n> w.padRight(\"clive\", 1, \"-\")\n'clive'\n> w.padRight(\"clive\", 10, \"-\")\n'clive-----'"
],
"returns": {
"type": "string",
"description": ""
}
},
{
"name": "exists",
"access": "",
"virtual": false,
"description": "",
"parameters": [],
"description": "returns true if a value, or nested object value exists in an array",
"parameters": [
{
"name": "array",
"type": "Array",
"description": "the array to search",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "value",
"type": "*",
"description": "the value to search for",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"exists([ 1, 2, 3 ], 2) // true\nexists([\n { result: false, number: 1 },\n { result: false, number: 2 }\n], { result: true }) // false"
]
"> w.exists([ 1, 2, 3 ], 2)\ntrue\n> w.exists([ { result: false }, { result: false } ], { result: true })\nfalse\n> w.exists([ { result: true }, { result: false } ], { result: true })\ntrue\n> w.exists([ { result: true }, { result: true } ], { result: true })\ntrue"
],
"returns": {
"type": "boolean",
"description": ""
}
},
{
"name": "without",
"access": "",
"virtual": false,
"description": "Returns the input array, minus the specied values",
"parameters": [
{
"name": "array",
"type": "Array",
"description": "the input array",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "toRemove",
"type": "*",
"description": "a single, or array of values to omit",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> w.without([ 1, 2, 3 ], 2)\n[ 1, 3 ]\n> w.without([ 1, 2, 3 ], [ 2, 3 ])\n[ 1 ]"
],
"returns": {
"type": "Array",
"description": ""
}
},
{
"name": "first",
"access": "",
"virtual": false,
"description": "Works on an array of objects. Returns the first object with `property` set to `value`.",
"parameters": [],
"examples": []
"description": "Returns the first object in the input array with `property` set to `value`.",
"parameters": [
{
"name": "objectArray",
"type": "Object[]",
"description": "input array of objects",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "prop",
"type": "string",
"description": "property to inspect",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "val",
"type": "*",
"description": "desired value",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> w.first([{ product: \"egg\", stock: true }, { product: \"chicken\", stock: true }], \"stock\", true)\n{ product: 'egg', stock: true }\n> w.first([{ product: \"egg\", stock: true }, { product: \"chicken\", stock: true }], \"stock\", false)\nundefined"
],
"returns": {
"type": [
"Object",
"undefined"
],
"description": ""
}
},

@@ -176,3 +479,5 @@ {

],
"examples": [],
"examples": [
"> files = fs.readdirSync(\".\").map(function(file){ return path.resolve(file); })\n[ '/Users/Lloyd/Documents/75lb/wodge/.DS_Store',\n '/Users/Lloyd/Documents/75lb/wodge/.git',\n '/Users/Lloyd/Documents/75lb/wodge/.gitignore',\n '/Users/Lloyd/Documents/75lb/wodge/.jshintrc',\n '/Users/Lloyd/Documents/75lb/wodge/README.md',\n '/Users/Lloyd/Documents/75lb/wodge/lib',\n '/Users/Lloyd/Documents/75lb/wodge/node_modules',\n '/Users/Lloyd/Documents/75lb/wodge/package.json',\n '/Users/Lloyd/Documents/75lb/wodge/test' ]\n> w.commonDir(files)\n'/Users/Lloyd/Documents/75lb/wodge/'"
],
"returns": {

@@ -182,3 +487,74 @@ "type": "string",

}
},
{
"name": "union",
"access": "",
"virtual": false,
"description": "merge two arrays into a single array of unique values",
"parameters": [],
"examples": [
"> var array1 = [ 1, 2 ], array2 = [ 2, 3 ];\nundefined\n> w.union(array1, array2)\n[ 1, 2, 3 ]\n> var array1 = [ { id: 1 }, { id: 2 } ], array2 = [ { id: 2 }, { id: 3 } ];\nundefined\n> w.union(array1, array2)\n[ { id: 1 }, { id: 2 }, { id: 3 } ]\n> var array2 = [ { id: 2, blah: true }, { id: 3 } ]\nundefined\n> w.union(array1, array2)\n[ { id: 1 },\n { id: 2 },\n { id: 2, blah: true },\n { id: 3 } ]\n> w.union(array1, array2, \"id\")\n[ { id: 1 }, { id: 2 }, { id: 3 } ]"
]
},
{
"name": "commonSequence",
"access": "",
"virtual": false,
"description": "Returns the initial elements which both input arrays have in common",
"parameters": [
{
"name": "a",
"type": "Array",
"description": "",
"default": "",
"optional": "",
"nullable": ""
},
{
"name": "b",
"type": "Array",
"description": "",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [
"> w.commonSequence([1,2,3], [1,2,4])\n[ 1, 2 ]"
],
"returns": {
"type": "Array",
"description": ""
}
},
{
"name": "escapeForJSON",
"access": "",
"virtual": false,
"description": "strips special characters, making suitable for storage in a JS/JSON string",
"parameters": [
{
"name": "input",
"type": "string",
"description": "the input",
"default": "",
"optional": "",
"nullable": ""
}
],
"examples": [],
"returns": {
"type": "string",
"description": ""
}
}
],
"properties": [
{
"name": "symbol",
"access": "",
"virtual": false,
"description": "some cross platform symbols (`tick` and `cross`)",
"type": ""
}
]

@@ -185,0 +561,0 @@ }

375

lib/wodge.js

@@ -5,2 +5,3 @@ "use strict";

/* The module API */
exports.extend = extend;

@@ -33,4 +34,7 @@ exports.clone = clone;

@example
w.extend({}, { one: 1, three: 3 }, { one: "one", two: 2 }, { four: 4 });
// { one: "one", two: 2, three: 3, four: 4 }
> w.extend({}, { one: 1, three: 3 }, { one: "one", two: 2 }, { four: 4 });
{ one: 'one',
three: 3,
two: 2,
four: 4 }
*/

@@ -49,12 +53,35 @@ function extend(){

/**
Returns a copy of the input object
@param {Object} input - the object to clone
@returns {Object}
Clones an object or array
@param {Object|Array} input - the input to clone
@returns {Object|Array}
@example
> date = new Date()
Fri May 09 2014 13:54:34 GMT+0200 (CEST)
> w.clone(date)
{} // a Date instance doensn't own any properties
> date.clive = "hater"
'hater'
> w.clone(date)
{ clive: 'hater' }
> array = [1,2,3]
[ 1, 2, 3 ]
> newArray = w.clone(array)
[ 1, 2, 3 ]
> array === newArray
false
*/
function clone(obj){
var output = {};
for (var prop in obj){
output[prop] = obj[prop];
function clone(input){
if (isPlainObject(input)){
var output = {};
for (var prop in input){
output[prop] = input[prop];
}
return output;
} else if (Array.isArray(input)){
var output = [];
input.forEach(function(item){
output.push(item);
});
return output;
}
return output;
}

@@ -64,12 +91,12 @@

Returns a clone of the input object, minus the specified properties
@param {Object} input - the object to clone
@param {string[]} toOmit - an array of property names to omit from the clone
@param {Object} - the object to clone
@param {string[]} - an array of property names to omit from the clone
@returns {Object}
@example
w.omit({ one: 1, two: 2, three: 3, four: 4 }, [ "two", "four" ]);
// { one: 1, three: 3 }
> w.omit({ one: 1, two: 2, three: 3, four: 4 }, [ "two", "four" ]);
{ one: 1, three: 3 }
*/
function omit(obj, toOmit){
function omit(object, toOmit){
toOmit = arrayify(toOmit);
var output = clone(obj);
var output = clone(object);
toOmit.forEach(function(omit){

@@ -84,4 +111,4 @@ delete output[omit];

@example
w.escapeRegExp("(.*)");
// '\\(\\.\\*\\)'
> w.escapeRegExp("(.*)");
'\\(\\.\\*\\)'
*/

@@ -100,16 +127,14 @@ function escapeRegExp(string){

@example
var data = [
{one: 1, two: 2},
{two: "two"},
{one: "one", two: "zwei"},
];
w.pluck(data, "one");
// [ 1, "one" ]
w.pluck(data, "two");
// [ 2, "two", "zwei" ]
w.pluck(data, "one", "two");
// [ 1, "two", "one" ]
> var data = [
... {one: 1, two: 2},
... {two: "two"},
... {one: "one", two: "zwei"},
... ];
undefined
> w.pluck(data, "one");
[ 1, 'one' ]
> w.pluck(data, "two");
[ 2, 'two', 'zwei' ]
> w.pluck(data, "one", "two");
[ 1, 'two', 'one' ]
*/

@@ -138,46 +163,136 @@ function pluck(arrayOfObjects, property, property2, property3){

/**
Returns true if input is a number
@example
> w.isNumber(0)
true
> w.isNumber(1)
true
> w.isNumber(1.1)
true
> w.isNumber(0xff)
true
> w.isNumber(0644)
true
> w.isNumber(6.2e5)
true
> w.isNumber(a)
false
> w.isNumber(NaN)
false
> w.isNumber(Infinity)
false
*/
function isNumber(n){
return !isNaN(parseFloat(n)) && isFinite(n);
}
function isPlainObject(o){
return typeof o === "object" && !Array.isArray(o);
/**
Returns true if input type is `object` and not an Array
@param {*} - the input to test
@returns {boolean}
@example
> w.isPlainObject(new Date())
true
> w.isPlainObject({ clive: "hater" })
true
> w.isPlainObject([ 0, 1 ])
false
*/
function isPlainObject(input){
return typeof input === "object" && !Array.isArray(input);
}
/**
Either:
Takes input and guarantees an array back. Result can be one of three things:
- puts a single scalar in an array
- converts array-like object to a real array
- converts array-like object (e.g. `arguments`) to a real array
- converts null or undefined to an empty array
@param {*} - the input value to convert to an array
@returns {Array}
@example
> w.arrayify(null)
[]
> w.arrayify(0)
[ 0 ]
> w.arrayify([ 1, 2 ])
[ 1, 2 ]
> function f(){ return w.arrayify(arguments); }
undefined
> f(1,2,3)
[ 1, 2, 3 ]
*/
function arrayify(arr){
if (arr === null || arr === undefined){
function arrayify(input){
if (input === null || input === undefined){
return [];
} else if (!Array.isArray(arr) && typeof arr === "object" && arr.length >= 0 && arr.length === Math.floor(arr.length)){
return Array.prototype.slice.call(arr);
} else if (isPlainObject(input) && input.length >= 0 && input.length === Math.floor(input.length)){
return Array.prototype.slice.call(input);
} else {
return Array.isArray(arr) ? arr : [ arr ];
return Array.isArray(input) ? input : [ input ];
}
}
function every(obj, callback){
var ev = true;
for (var prop in obj){
ev = ev && callback(obj[prop], prop);
/**
Returns true if the supplied iterator function returns true for every property in the object
@param {Object} - the object to inspect
@param {Function} - the iterator function to run against each key/value pair, the args are `(value, key)`.
@returns {Boolean}
@example
> function aboveTen(input){ return input > 10; }
undefined
> w.every({ eggs: 12, carrots: 30, peas: 100 }, aboveTen)
true
> w.every({ eggs: 6, carrots: 30, peas: 100 }, aboveTen)
false
*/
function every(object, iterator){
var result = true;
for (var prop in object){
result = result && iterator(object[prop], prop);
}
return ev;
return result;
}
function each(obj, callback){
for (var prop in obj){
callback(obj[prop], prop);
/**
Runs the iterator function against every key/value pair in the input object
@param {Object} - the object to iterate
@param {Function} - the iterator function to run against each key/value pair, the args are `(value, key)`.
@example
> var total = 0;
undefined
> function addToTotal(n){ total += n; }
undefined
> w.each({ eggs: 3, celery: 2, carrots: 1 }, addToTotal)
undefined
> total
6
*/
function each(object, callback){
for (var prop in object){
callback(object[prop], prop);
}
}
/**
Convert bytes to human-readable size
@param {number} - the bytes value to convert
@param {number} [precision=0] - number of decimal places
@returns {string}
@example
> w.bytesToSize(10000)
'10 KB'
> w.bytesToSize(10000, 1)
'9.8 KB'
> w.bytesToSize(10000, 2)
'9.77 KB'
> w.bytesToSize(10000, 3)
'9.766 KB'
*/
function bytesToSize(bytes, precision){
var kilobyte = 1024;
var megabyte = kilobyte * 1024;
var gigabyte = megabyte * 1024;
var terabyte = gigabyte * 1024;
var kilobyte = 1024,
megabyte = kilobyte * 1024,
gigabyte = megabyte * 1024,
terabyte = gigabyte * 1024;

@@ -206,3 +321,5 @@ if ((bytes >= 0) && (bytes < kilobyte)) {

Cross-platform home directory retriever
@method
@example
> w.getHomeDir()
'/Users/Lloyd'
*/

@@ -213,2 +330,13 @@ function getHomeDir() {

/**
Create a new string filled with the supplied character
@param {string} - the fill character
@param {number} - the length of the output string
@returns {string}
@example
> w.fill("a", 10)
'aaaaaaaaaa'
> w.fill("ab", 10)
'aaaaaaaaaa'
*/
function fill(fillWith, len){

@@ -219,2 +347,17 @@ var buffer = new Buffer(len);

}
/**
Add padding to the right of a string
@param {string} - the string to pad
@param {number} - the desired final width
@param {string} [padWith=" "] - the padding character
@returns {string}
@example
> w.padRight("clive", 1)
'clive'
> w.padRight("clive", 1, "-")
'clive'
> w.padRight("clive", 10, "-")
'clive-----'
*/
function padRight(input, width, padWith){

@@ -230,11 +373,17 @@ padWith = padWith || " ";

/**
returns true if a value, or nested object value exists in an array
@param {Array} - the array to search
@param {*} - the value to search for
@returns {boolean}
@example
exists([ 1, 2, 3 ], 2) // true
exists([
{ result: false, number: 1 },
{ result: false, number: 2 }
], { result: true }) // false
> w.exists([ 1, 2, 3 ], 2)
true
> w.exists([ { result: false }, { result: false } ], { result: true })
false
> w.exists([ { result: true }, { result: false } ], { result: true })
true
> w.exists([ { result: true }, { result: true } ], { result: true })
true
*/
function exists(arr, value){
function exists(array, value){
if (isPlainObject(value)){

@@ -246,3 +395,3 @@ var query = value,

while(!found && (item = arr[index++])){
while(!found && (item = array[index++])){
for (var prop in query){

@@ -255,9 +404,20 @@ found = query[prop] === item[prop];

} else {
return arr.indexOf(value) > -1;
return array.indexOf(value) > -1;
}
}
function without(arr, toRemove){
/**
Returns the input array, minus the specied values
@param {Array} - the input array
@param {*} - a single, or array of values to omit
@returns {Array}
@example
> w.without([ 1, 2, 3 ], 2)
[ 1, 3 ]
> w.without([ 1, 2, 3 ], [ 2, 3 ])
[ 1 ]
*/
function without(array, toRemove){
toRemove = arrayify(toRemove);
return arr.filter(function(item){
return array.filter(function(item){
return !exists(toRemove, item);

@@ -268,6 +428,15 @@ });

/**
Works on an array of objects. Returns the first object with `property` set to `value`.
Returns the first object in the input array with `property` set to `value`.
@param {Object[]} - input array of objects
@param {string} - property to inspect
@param {*} - desired value
@returns {Object|undefined}
@example
> w.first([{ product: "egg", stock: true }, { product: "chicken", stock: true }], "stock", true)
{ product: 'egg', stock: true }
> w.first([{ product: "egg", stock: true }, { product: "chicken", stock: true }], "stock", false)
undefined
*/
function first(arr, prop, val){
var result = arr.filter(function(item){
function first(objectArray, prop, val){
var result = objectArray.filter(function(item){
return item[prop] ? item[prop] === val : false;

@@ -282,2 +451,15 @@ });

@returns {string} - A single path ending with the path separator, e.g. "/user/some/folder/"
@example
> files = fs.readdirSync(".").map(function(file){ return path.resolve(file); })
[ '/Users/Lloyd/Documents/75lb/wodge/.DS_Store',
'/Users/Lloyd/Documents/75lb/wodge/.git',
'/Users/Lloyd/Documents/75lb/wodge/.gitignore',
'/Users/Lloyd/Documents/75lb/wodge/.jshintrc',
'/Users/Lloyd/Documents/75lb/wodge/README.md',
'/Users/Lloyd/Documents/75lb/wodge/lib',
'/Users/Lloyd/Documents/75lb/wodge/node_modules',
'/Users/Lloyd/Documents/75lb/wodge/package.json',
'/Users/Lloyd/Documents/75lb/wodge/test' ]
> w.commonDir(files)
'/Users/Lloyd/Documents/75lb/wodge/'
*/

@@ -295,15 +477,46 @@ function commonDir(files){

/**
merge two arrays into a single array of unique values
@example
> var array1 = [ 1, 2 ], array2 = [ 2, 3 ];
undefined
> w.union(array1, array2)
[ 1, 2, 3 ]
> var array1 = [ { id: 1 }, { id: 2 } ], array2 = [ { id: 2 }, { id: 3 } ];
undefined
> w.union(array1, array2)
[ { id: 1 }, { id: 2 }, { id: 3 } ]
> var array2 = [ { id: 2, blah: true }, { id: 3 } ]
undefined
> w.union(array1, array2)
[ { id: 1 },
{ id: 2 },
{ id: 2, blah: true },
{ id: 3 } ]
> w.union(array1, array2, "id")
[ { id: 1 }, { id: 2 }, { id: 3 } ]
*/
function union(array1, array2, idKey){
var result = clone(array1);
array2.forEach(function(item){
if (idKey){
if (!first(array1, idKey, item[idKey])){
array1.push(item);
if (!first(result, idKey, item[idKey])){
result.push(item);
}
} else if (!exists(array1, item)){
array1.push(item);
} else if (!exists(result, item)){
result.push(item);
};
});
return array1;
return result;
}
/**
Returns the initial elements which both input arrays have in common
@param {Array} - first array to compare
@param {Array} - second array to compare
@returns {Array}
@example
> w.commonSequence([1,2,3], [1,2,4])
[ 1, 2 ]
*/
function commonSequence(a, b){

@@ -319,4 +532,12 @@ var result = [];

function escapeForJSON (str) {
return str
/**
strips special characters, making suitable for storage in a JS/JSON string
@param {string} - the input
@returns {string}
@example
> w.escapeForJSON("hello\nthere")
'hello\\nthere'
*/
function escapeForJSON (input) {
return input
.replace(/[\\]/g, '\\\\')

@@ -332,2 +553,6 @@ .replace(/[\/]/g, '\\/')

/**
some cross platform symbols (`tick` and `cross`)
@returns {Object}
*/
var symbol = {

@@ -334,0 +559,0 @@ tick: process.platform === "win32" ? "\u221A" : "✔︎",

{
"name": "wodge",
"version": "0.6.1",
"version": "0.6.2",
"description": "a wodge of functional dough",

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

@@ -18,16 +18,36 @@ [![view on npm](http://img.shields.io/npm/v/wodge.svg)](https://www.npmjs.org/package/wodge)

###Parameters
object {Object} - a sequence of Object instances to be extended
object {Object} - a sequence of Object instances to be extended
###Example
```js
w.extend({}, { one: 1, three: 3 }, { one: "one", two: 2 }, { four: 4 });
// { one: "one", two: 2, three: 3, four: 4 }
> w.extend({}, { one: 1, three: 3 }, { one: "one", two: 2 }, { four: 4 });
{ one: 'one',
three: 3,
two: 2,
four: 4 }
```
##clone
Returns a copy of the input object
Clones an object or array
###Parameters
input {Object} - the object to clone
input {Object,Array} - the input to clone
**Returns** Object
###Example
```js
> date = new Date()
Fri May 09 2014 13:54:34 GMT+0200 (CEST)
> w.clone(date)
{} // a Date instance doensn't own any properties
> date.clive = "hater"
'hater'
> w.clone(date)
{ clive: 'hater' }
> array = [1,2,3]
[ 1, 2, 3 ]
> newArray = w.clone(array)
[ 1, 2, 3 ]
> array === newArray
false
```
**Returns** Object,Array

@@ -38,9 +58,9 @@ ##omit

###Parameters
input {Object} - the object to clone
toOmit {string[]} - an array of property names to omit from the clone
object {Object} - the object to clone
toOmit {string[]} - an array of property names to omit from the clone
###Example
```js
w.omit({ one: 1, two: 2, three: 3, four: 4 }, [ "two", "four" ]);
// { one: 1, three: 3 }
> w.omit({ one: 1, two: 2, three: 3, four: 4 }, [ "two", "four" ]);
{ one: 1, three: 3 }
```

@@ -54,4 +74,4 @@ **Returns** Object

```js
w.escapeRegExp("(.*)");
// '\\(\\.\\*\\)'
> w.escapeRegExp("(.*)");
'\\(\\.\\*\\)'
```

@@ -62,46 +82,240 @@ ##pluck

###Parameters
arrayOfObjects {Object[]} - the input array of objects
the {string} - property to pluck
arrayOfObjects {Object[]} - the input array of objects
the {string} - property to pluck
###Example
```js
var data = [
{one: 1, two: 2},
{two: "two"},
{one: "one", two: "zwei"},
];
> var data = [
... {one: 1, two: 2},
... {two: "two"},
... {one: "one", two: "zwei"},
... ];
undefined
> w.pluck(data, "one");
[ 1, 'one' ]
> w.pluck(data, "two");
[ 2, 'two', 'zwei' ]
> w.pluck(data, "one", "two");
[ 1, 'two', 'one' ]
```
**Returns** Array
w.pluck(data, "one");
// [ 1, "one" ]
##isNumber
Returns true if input is a number
w.pluck(data, "two");
// [ 2, "two", "zwei" ]
###Example
```js
> w.isNumber(0)
true
> w.isNumber(1)
true
> w.isNumber(1.1)
true
> w.isNumber(0xff)
true
> w.isNumber(0644)
true
> w.isNumber(6.2e5)
true
> w.isNumber(a)
false
> w.isNumber(NaN)
false
> w.isNumber(Infinity)
false
```
##isPlainObject
Returns true if input type is `object` and not an Array
w.pluck(data, "one", "two");
// [ 1, "two", "one" ]
###Parameters
input {*} - the input to test
###Example
```js
> w.isPlainObject(new Date())
true
> w.isPlainObject({ clive: "hater" })
true
> w.isPlainObject([ 0, 1 ])
false
```
**Returns** Array
**Returns** boolean
##arrayify
Either:
Takes input and guarantees an array back. Result can be one of three things:
- puts a single scalar in an array
- converts array-like object to a real array
- converts array-like object (e.g. `arguments`) to a real array
- converts null or undefined to an empty array
###Parameters
input {*} - the input value to convert to an array
###Example
```js
> w.arrayify(null)
[]
> w.arrayify(0)
[ 0 ]
> w.arrayify([ 1, 2 ])
[ 1, 2 ]
> function f(){ return w.arrayify(arguments); }
undefined
> f(1,2,3)
[ 1, 2, 3 ]
```
**Returns** Array
##every
Returns true if the supplied iterator function returns true for every property in the object
###Parameters
object {Object} - the object to inspect
iterator {function} - the iterator function to run against each key/value pair, the args are `(value, key)`.
###Example
```js
> function aboveTen(input){ return input > 10; }
undefined
> w.every({ eggs: 12, carrots: 30, peas: 100 }, aboveTen)
true
> w.every({ eggs: 6, carrots: 30, peas: 100 }, aboveTen)
false
```
**Returns** Boolean
##each
Runs the iterator function against every key/value pair in the input object
###Parameters
object {Object} - the object to iterate
callback {function} - the iterator function to run against each key/value pair, the args are `(value, key)`.
###Example
```js
> var total = 0;
undefined
> function addToTotal(n){ total += n; }
undefined
> w.each({ eggs: 3, celery: 2, carrots: 1 }, addToTotal)
undefined
> total
6
```
##bytesToSize
Convert bytes to human-readable size
###Parameters
bytes {number} - the bytes value to convert
precision {number} - number of decimal places *optional* *default=0*
###Example
```js
> w.bytesToSize(10000)
'10 KB'
> w.bytesToSize(10000, 1)
'9.8 KB'
> w.bytesToSize(10000, 2)
'9.77 KB'
> w.bytesToSize(10000, 3)
'9.766 KB'
```
**Returns** string
##getHomeDir
Cross-platform home directory retriever
###Example
```js
> w.getHomeDir()
'/Users/Lloyd'
```
##fill
Create a new string filled with the supplied character
###Parameters
fillWith {string} - the fill character
len {number} - the length of the output string
###Example
```js
> w.fill("a", 10)
'aaaaaaaaaa'
> w.fill("ab", 10)
'aaaaaaaaaa'
```
**Returns** string
##padRight
Add padding to the right of a string
###Parameters
input {string} - the string to pad
width {number} - the desired final width
padWith {string} - the padding character *optional* *default=" "*
###Example
```js
> w.padRight("clive", 1)
'clive'
> w.padRight("clive", 1, "-")
'clive'
> w.padRight("clive", 10, "-")
'clive-----'
```
**Returns** string
##exists
returns true if a value, or nested object value exists in an array
###Parameters
array {Array} - the array to search
value {*} - the value to search for
###Example
```js
exists([ 1, 2, 3 ], 2) // true
exists([
{ result: false, number: 1 },
{ result: false, number: 2 }
], { result: true }) // false
> w.exists([ 1, 2, 3 ], 2)
true
> w.exists([ { result: false }, { result: false } ], { result: true })
false
> w.exists([ { result: true }, { result: false } ], { result: true })
true
> w.exists([ { result: true }, { result: true } ], { result: true })
true
```
**Returns** boolean
##without
Returns the input array, minus the specied values
###Parameters
array {Array} - the input array
toRemove {*} - a single, or array of values to omit
###Example
```js
> w.without([ 1, 2, 3 ], 2)
[ 1, 3 ]
> w.without([ 1, 2, 3 ], [ 2, 3 ])
[ 1 ]
```
**Returns** Array
##first
Works on an array of objects. Returns the first object with `property` set to `value`.
Returns the first object in the input array with `property` set to `value`.
###Parameters
objectArray {Object[]} - input array of objects
prop {string} - property to inspect
val {*} - desired value
###Example
```js
> w.first([{ product: "egg", stock: true }, { product: "chicken", stock: true }], "stock", true)
{ product: 'egg', stock: true }
> w.first([{ product: "egg", stock: true }, { product: "chicken", stock: true }], "stock", false)
undefined
```
**Returns** Object,undefined
##commonDir

@@ -111,6 +325,66 @@ commonDir returns the directory common to each path in the list

###Parameters
files {Array} - An array of file paths to inspect
files {Array} - An array of file paths to inspect
**Returns** string - A single path ending with the path separator, e.g. &quot;/user/some/folder/&quot;
###Example
```js
> files = fs.readdirSync(".").map(function(file){ return path.resolve(file); })
[ '/Users/Lloyd/Documents/75lb/wodge/.DS_Store',
'/Users/Lloyd/Documents/75lb/wodge/.git',
'/Users/Lloyd/Documents/75lb/wodge/.gitignore',
'/Users/Lloyd/Documents/75lb/wodge/.jshintrc',
'/Users/Lloyd/Documents/75lb/wodge/README.md',
'/Users/Lloyd/Documents/75lb/wodge/lib',
'/Users/Lloyd/Documents/75lb/wodge/node_modules',
'/Users/Lloyd/Documents/75lb/wodge/package.json',
'/Users/Lloyd/Documents/75lb/wodge/test' ]
> w.commonDir(files)
'/Users/Lloyd/Documents/75lb/wodge/'
```
**Returns** string - A single path ending with the path separator, e.g. "/user/some/folder/"
##union
merge two arrays into a single array of unique values
###Example
```js
> var array1 = [ 1, 2 ], array2 = [ 2, 3 ];
undefined
> w.union(array1, array2)
[ 1, 2, 3 ]
> var array1 = [ { id: 1 }, { id: 2 } ], array2 = [ { id: 2 }, { id: 3 } ];
undefined
> w.union(array1, array2)
[ { id: 1 }, { id: 2 }, { id: 3 } ]
> var array2 = [ { id: 2, blah: true }, { id: 3 } ]
undefined
> w.union(array1, array2)
[ { id: 1 },
{ id: 2 },
{ id: 2, blah: true },
{ id: 3 } ]
> w.union(array1, array2, "id")
[ { id: 1 }, { id: 2 }, { id: 3 } ]
```
##commonSequence
Returns the initial elements which both input arrays have in common
###Parameters
a {Array} -
b {Array} -
###Example
```js
> w.commonSequence([1,2,3], [1,2,4])
[ 1, 2 ]
```
**Returns** Array
##escapeForJSON
strips special characters, making suitable for storage in a JS/JSON string
###Parameters
input {string} - the input
**Returns** string

Sorry, the diff of this file is not supported yet

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