data-stapler
v1.5.0
Published
Easily manipulate arrays, objects, and strings!
Downloads
8
Maintainers
Readme
data-stapler
allows you to do fun things with your Node.JS arrays, objects, and strings!
Install
npm i data-stapler
Basic Example
Example: Merging 2 objects together. For this we are going to be using the stapler.merge()
async
function.
let Stapler = require('data-stapler');
let stapler = new Stapler();
let myObj1 = {
"NODE": "IS FUN"
}
let myObj2 = {
"NOT": "LYING"
}
stapler.mergeObject(myObj1, myObj2)
.then((combined) => console.log(combined)); // Will log: { NODE: "IS FUN", "NOT": "LYING" }
Merging 2 arrays.
let Stapler = require('data-stapler');
let stapler = new Stapler();
let a1 = ["Hello", "world", "What a beautiful"];
let a2 = ["day", "today!"];
stapler.mergeArray(a1, a2)
.then((combined) => console.log(combined)); // Will log: [ 'Hello', 'world', 'What a beautiful', 'day', 'today!' ]
Staple Functionality
Use this to staple as many objects and arrays as you want!
let Stapler = require('data-stapler');
let stapler = new Stapler();
let myObj1 = {
"NODE": "IS FUN"
}
let myObj2 = {
"NOT": "LYING"
}
let myObj3 = {
"THIS": "IS COOL!"
}
let a1 = ["Hello", "world", "What a beautiful"];
let a2 = ["day", "today!"];
let a3 = ["I love", "pickles!"]
stapler.stapleObject([myObj1, myObj2, myObj3])
.then((combinedo) => console.log(combinedo));
stapler.stapleArray([a1, a2, a3])
.then((combinedarr) => console.log(combinedarr));
Configuration
You can configure your stapler instance to allow a minimum and maximum amount of arrays/objects to allow to be stapled at once.
let Stapler = require('data-stapler');
const staplerconfig = {
min: 3, //Minimum of 3 staples
max: 8 // Maximum of 8 staples
}
let stapler = new Stapler(staplerconfig);
Preferring async
over object [Promise]
If you prefer against promises, you can always use async
functions. Example:
let Stapler = require('data-stapler');
const staplerconfig = {
min: 1, //Minimum of 1 staples
max: 60 // Maximum of 60 staples
}
let stapler = new Stapler(staplerconfig);
async function staple(stuff) {
let resp = await stapler.stapleArray(stuff);
return resp;
}
let something = await staple([["Yes"], ["Sir"]])
console.log(something) // WIll log: ["Yes", "Sir"]
String Operation
You can convert arrays to strings and strings to arrays!
let Stapler = require('data-stapler');
let stapler = new Stapler({ min: 1, max: 500 });
let a4 = ["N", "o", "d", "e"];
let hi = "Node is the best lang ever!"
stapler.arrayToString(a4)
.then((newstr) => console.log(newstr)); // Will log: "Node"
stapler.stringToArray(hi)
.then((newarr) => console.log(newarr)); /* Will log:
[
'N', 'o', 'd', 'e', ' ', 'i',
's', ' ', 't', 'h', 'e', ' ',
'b', 'e', 's', 't', ' ', 'l',
'a', 'n', 'g', ' ', 'e', 'v',
'e', 'r', '!'
]
*/
Author
Tyler K.