Between-Join
Join array between expression for NodeJS
What's this?
This is a simple library for generate string (of object or array)
Installation
Between-Join requires Node.js v8+ to run.
Install the dependencies and start the server.
$ cd yourProject
$ npm install between-join --save
Parameters
BetweenJoin must receive 3 parametters (2 required):
1) Object / Array [Required]
2) Expression [Required]
- Expression must contain '$1' key, and/or $2 if is jsobject
- Objects:
- $1 = Object key
- $2 = Object value
3) Delete [Optional]
- Numeric param, erase last characters (1, ..., response.length)
Expression
Between-join must receive to parameter, 'expression'. The word '$1' into expression will be replaced by value of array and '$1' and '$2' for object
const exp = '>$1<';
Examples
Array
Code:
const BetweenJoin = require('between-join');
const array = ['Hola', 'Mundo'];
const expression = '[$1]';
const response = BetweenJoin(array, expression);
console.log(response);
Output
[Hello][World]
Object
Code:
const BetweenJoin = require('between-join');
const obj = {
hola: 'World',
key: 'Value',
};
const expression = '[$1-$2]';
const response = BetweenJoin(obj, expression);
console.log(response);
Output
[hola-World][key-Value]
Object and array
Code:
const BetweenJoin = require('between-join');
const values = {
array: ['Hello', 'World'],
obj: {
print: 'I\'m a js object',
},
};
const expression = '[$1 $2]';
const response = BetweenJoin(values, expression);
console.log(response);
Output
[array [Hello][World]][obj[printI'm a js object]]
Deleting last character
const BetweenJoin = require('between-join');
const array = ['Hello', 'World'];
const expression = '[$1]';
const normal = BetweenJoin(array, expression);
const one = BetweenJoin(array, expression, 1);
const two = BetweenJoin(array, expression, 2);
console.log(normal);
console.log(one);
console.log(two);
Output
[Hello][World]
[Hello][World
[Hello][Worl