Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A set of sexy little helper, to make the daily work with nodeJS a bit easier.
A set of sexy little helper, to make the daily work with nodeJS a bit easier :-)
$ npm install toolbelt
To run the tests first invoke the following command to install all dev dependencies.
$ npm install
Run the tests with
$ npm test
Load and use a module:
var module = require('toolbelt').pick([module_namespace]);
var data = module([do_your_thing]);
Merge the contents of two or more objects/arrays together into the first object/array.
extend([deepCopy,] target [, object1] [, objectN] );
Shallow extend
var extend = require('toolbelt').pick('base/extend');
var data = extend({a:1},{b:2});
Deep extend
var extend = require('toolbelt').pick('base/extend');
var data = extend(true,{a:1},{b:2});
A extend version of "hasOwnProperty" tests if a object has a certain structure.
has(object, path);
var has = require('toolbelt').pick('base/has');
var data = {foo:{bar:{baz:1}}};
var hasPath = has(data,'foo.bar.baz'); // returns true
var hasPath = has(data,'foo.bar.nuv'); // returns false
Modifies a stack of data and returns the result.
stack(stack, worker, callback);
Takes a stack of numbers and increments them by 1
var stack = require('toolbelt').pick('base/stack');
var list = [1,2,3,4,5];
var worker = function(data,cb){
// LONNNGGG Calculation :-)
setTimeout(function() {
data = data+1;
cb(false,data);
},100);
};
var callback = function(err, data){
if(err) throw new Error('Upps');
console.log(data);
}
stack(list, worker, callback); // returns [2,3,4,5,6];
Generates a UUID
uuid();
var uuid = require('toolbelt').pick('base/uuid');
var myId = uuid(); // returns [random uuid]
Format a local date/time. Its basicaly a port from PHPs date() function. For more info on the format string see function.date-Page.
date(format, [Date]);
var date = require('toolbelt').pick('format/date');
var testTime = new Date();
var dateFormarted = date('Y-m-d H:i:s',testTime); // returns "2012-08-07 17:39:27"
Formats a Number/Float/Double.
money(amount,radix,ThsSeperator,DecDelimiter);
var money = require('toolbelt').pick('format/money');
var formatedString = money(1000.111, 2, '.',','); // returns "1,000.11"
Returns a random position from a number, hash, string or array
item(list);
var ritem = require('toolbelt').pick('rand/item');
var entry = ritem([0,1,2,3,4]); // returns random integer from array
var entry = ritem('ABC'); // returns random position from string
var entry = ritem({a:1,b:2}); // returns a random key from a hash
var entry = ritem(123); // returns a random pos from the number [1|2|3]
Returns a random number limited by a specified upper threshold.
rmax(maxVal,[floatVal]);
var rmax = require('toolbelt').pick('rand/max');
var entry = rmax(4); // returns random integer <= 4
var entry = rmax(4,1); // returns random integer <= 4.0
Returns a random number limited by a upper and lower threshold.
rbetween(minVal, maxVal,[floatVal]);
var rbetween = require('toolbelt').pick('rand/between');
var entry = rmax(1,4); // returns random integer <= 4
var entry = rmax(1,4,1); // returns random integer <= 4.0
Asynchronously copies a file from a source to a destination
copy(source,destination,callback);
var copy = require('toolbelt').pick('fs/copy');
copy('/tmp/a.txt','/tmp/b.txt',function(err) {
if(err) throw Error('Copy failed!');
});
Synchronously copies a file from a source to a destination
copy(source,destination);
var copySync = require('toolbelt').pick('fs/copySync');
copySync('/tmp/a.txt','/tmp/b.txt');
Walks a directory recusive in parallel and lists all files in it.
dirwalkParallel(path,callback);
var dirwalkParallel = require('toolbelt').pick('fs/dirwalkParallel');
dirwalkParallel('/tmp',function(err,data){
if(err) throw new Error('Error');
console.log(data); // Array with all files in subdirectory
});
Walks a directory recusive in seriel (one-by-one) and lists all files in it.
dirwalkParallel(path,callback);
var dirwalkSeriel = require('toolbelt').pick('fs/dirwalkSeriel');
dirwalkSeriel('/tmp',function(err,data){
if(err) throw new Error('Error');
console.log(data); // Array with all files in subdirectory
});
Returns the parent directory for a given path.
parentdir(path);
var parentdir = require('toolbelt').pick('fs/parentdir');
parentdir('C:\A\B\C'); // Returns: C:\A\B
parentdir('C:\A\B\C.html'); // Returns: C:\A\B
parentdir('.'); // Returns: Parent from current working directory
parentdir('..'); // Returns: Parents Parent from current working directory etc. ...
parentdir('..','/A/B/C'; // Returns: '/A/B'
Sort a list/queue of objects by an identifier/key.
sortqueue(queue,key,sort);
var list = [
{id:2},
{id:4},
{id:1},
{id:3}
];
var numericSort = function(a,b){
return a-b;
}
var sortqueue = require('toolbelt').pick('sort/queue');
var sortedList = sortqueue(list,'id',numericSort);
// sortedList is now:
//[
// {id:1},
// {id:2},
// {id:3},
// {id:4}
//]
Natural sort algorithm in Javascript. Can be used together with Array.sort as a comperator.
natsort(a,b);
var natsort = require('toolbelt').pick('sort/natsort');
var ipList = [
'10.5.1.1',
'10.5.1.6',
'10.5.2.2'
];
var ipListSorted = ipList.sort(natsort);
WordWrap for Hipsters.
wordwrap(str [,width] [,fill] [,brk] [,cut]);
var wordwrap = require('toolbelt').pick('txt/wordwrap');
var wrapedTxt = wordwrap('Thundercats polaroid sartorial synth messenger bag wes anderson.', 20, '<br/>\n');
// returns
// Thundercats polaroid <br/>\n
// sartorial synth <br/>\n
// messenger bag wes <br/>\n
// anderson.
WordWrap for Hipsters. A iOS like wordwarp that shorts a Text in the middle deppending on its length.
iwordwrap(str [, length] [,fill]);
var iwordwrap = require('toolbelt').pick('txt/iwordwrap');
var res = iwordwrap('CaWaBunGa-CaWaBunGa'); // returns "CaWaB...unGa";
###(The MIT License)
#####Copyright (c) 2010-2012 Alexander Pirsig self@pirsig.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
A set of sexy little helper, to make the daily work with nodeJS a bit easier.
The npm package toolbelt receives a total of 5 weekly downloads. As such, toolbelt popularity was classified as not popular.
We found that toolbelt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.