Toolbox - Rest #
This package gives functions to use and reuse anywhere. It offers simplied Rest functionnalitoes as well
Dependencies ##
- pretty-data
- request
- xml2js
- moment
How to install? ##
~~~
npm install --save bdt105toolbox
~~~
Rest #
Rest functions
How to use? ##
Create an object Toolbox
~~~
import { Rest } from "bdt105toolbox/dist";
let logFile = "logFile.log";
let logToConsole = true;
let rest = new Rest(logFile, logToconsole);
~~~
logFile and logToConsole are optional. They trace each call.
Functions ##
$3
Call a http or https url and calls callback function when done. getRaw retreives untransformed result of the call.
Toolbox #
Series of usefull functions.
How to use? ##
Create an object Toolbox
~~~
import { Toolbox } from "bdt105toolbox/dist";
let toolbox = new Toolbox();
~~~
Functions ##
$3
Formats a date usable by MySql, format: "yyyy-MM-dd HH:mm:ss"
$3
Transforms an iso date into MySql format: "yyyy-MM-ddTHH:mm:ss" => "yyyy-MM-dd HH:mm:ss"
$3
Transforms into an array a csv line. Separator is ";"
$3
Transforms into a csv string an array.
$3
Calculate Levenshtein distance between two strings.
$3
Transforms an array of objects into a string. Mainly used to create sql where strings.
~~~
arrayOfObjectsToString([
{"fieldName": "firstName"},
{"fieldName": "lastName"},
{"fieldName": "email"}], "fieldName", "value", "AND", "like '%", "%'")
~~~
becomes
~~~
firstName like '%value%' AND lastName like '%value%' AND email like '%value%'
~~~
$3
Transforms the params of an url into an object.
~~~
http://www.url.com?param1=1¶m2=2¶m3=3
~~~
becomes
~~~
{"param1": 1, "param2": 2, "param3": 3}
~~~
$3
Gets the base of an url.
~~~
http://www.url.com?param1=1¶m2=2¶m3=3
~~~
becomes
~~~
http://www.url.com
~~~
$3
Retreives the entries of an array of objects matching the filter keySearch == keyValue.
$3
Retreives the index of an array of objects matching the filter keySearch == keyValue. First value found is retreived.
$3
For an array of flat objects will create a master slave array of objects.
~~~
factorizeMasterSlave(
[
{"customerId": 1, "customerName": "customerName1", "orderId": 11, "orderDescription": "order11"},
{"customerId": 1, "customerName": "customerName1", "orderId": 12, "orderDescription": "order12"},
{"customerId": 1, "customerName": "customerName1", "orderId": 13, "orderDescription": "order13"},
{"customerId": 2, "customerName": "customerName2", "orderId": 21, "orderDescription": "order21"},
{"customerId": 2, "customerName": "customerName2", "orderId": 22, "orderDescription": "order22"},
{"customerId": 2, "customerName": "customerName2", "orderId": 23, "orderDescription": "order23"}
], "customerId", "orderId", "orders");
~~~
becomes
~~~
[
{"customerId": 1, "customerName": "customerName1",
"orders": [
{"orderId": 11, "orderDescription": "order11"}
{"orderId": 12, "orderDescription": "order12"}
{"orderId": 13, "orderDescription": "order13"}
]
},
{"customerId": 2, "customerName": "customerName2",
"orders": [
{"orderId": 21, "orderDescription": "order21"}
{"orderId": 22, "orderDescription": "order22"}
{"orderId": 23, "orderDescription": "order23"}
]
}
]
~~~
$3
Updates a parameter within a an url.
$3
Updates parameters within a an url. Parameters must an array of object of type {"key": "", "value": ""}
$3
Retreives a array of object of type {"key": "", "value": ""} from an url
$3
Deletes empty paramters from an url
$3
Delete elements in a csv like string.
$3
Concats source into destination.
$3
Remove a records from an array according to a key. Array must contain objects with at least a "key" field.
$3
Checks if a date is valid.
$3
Transforms a date into french date format ("dd-MM-yyyy HH:mm:ss")
$3
Removes time information from a date
$3
Gets the difference in days between two dates
$3
Logs information into a file. All lines are prefixed by timestamp of the append in the log file.
$3
Adds data into an elasticsearch server
$3
Retreive an object of the json contained into a file
$3
Retreives a unique id base on random 16bit from library "crypto"
$3
Retreives beautifull string containg xml. Based on pretty-data library
$3
Retreives beautifull string containg json. Based on pretty-data library
$3
Writes to local browser storage. If forever then localStorage is used if not seesionStorage is used
$3
Retreives an object from a Json string
$3
Gets object from sessionStorage, if not found from localStorage
$3
REmoves object from sessionStorage and localStorage
$3
Transforms a xml string into Json object. Based on https://github.com/Leonidas-from-XIV/node-xml2js
$3
Fills DOM document with string