A set of application utilities that will come in useful in Node.js
npm install @siraglovale/utils
This module should be imported into your entry point, this will then setup global functions that can be used within your project.
Sets the application specific information within the node project
- _application_: <Object>
- name: <string>
- version: <string>
Log to stdout a message with a timestamp and information about the application
- _message_: <any>
Log to stderr a message with a timestamp and information about the application
- _message_: <any>
Converts an ascii string to a base64 string
- _ascii_: <string>
Converts an ascii string to a hex string
- _ascii_: <string>
Converts an ascii string to a utf-8 string
- _ascii_: <string>
Converts an ascii string to a utf-16 little endian string
- _ascii_: <string>
Converts a base64 string to an ascii string
- _base64_: <string>
Converts a base64 string to a hex string
- _base64_: <string>
Converts a base64 string to a utf-8 string
- _base64_: <string>
Converts a base64 string to a utf-16 little endian string
- _base64_: <string>
Converts a hex string to an ascii string
- _hex_: <string>
Converts a hex string to a base64 string
- _hex_: <string>
Converts a hex string to a utf-8 string
- _hex_: <string>
Converts a hex string to a utf-16 little endian string
- _hex_: <string>
Converts a utf8 string to an ascii string
- _utf8_: <string>
Converts a utf8 string to a base64 string
- _utf8_: <string>
Converts a utf8 string to a hex string
- _utf8_: <string>
Converts a utf8 string to a utf-16 little endian string
- _utf8_: <string>
Hash your password with a pseudo-randomly generated salt.
- password: <string>
- secret: <string> CONSTANT
Hash a password with bcrypt
- password: <string>
- saltRounds: <number>
Hash a password with bcrypt synchronously
- password: <string>
- saltRounds: <number>
Validate a submitted password against a hash stored in your database
- password: <string>
- hash: <string>
- secret: <string> CONSTANT
Validates a bcrypt password
- password: <string>
- hash: <string>
Validates a bcrypt password synchronously
- password: <string>
- hash: <string>
Generate a secret for use in 2 Factor Authentication, this is used to generate the TOTP
- _email: <string>
Generate a QR Code for the user based of the secret generated using genSecret, to use in conjunction with Google Authenticator, Authy or similar
- _email: <string>
- _secret: <string>
Returns an object that the token relates to, and, verifies the user
- _token: <string>
- _secret: <string>
let utils = require("@siraglovale/utils"); // require module
utils.setApplication({
name: "application_1",
version: "0.1.0"
});
log("Hello World!");
// stdout
// application_1@0.1.0[Thu Sep 14 2017 22:41:48 GMT+0100 (GMT Summer Time)] -> Hello World!
error("error");
// stderr
// application_1@0.1.0[Thu Sep 14 2017 22:41:48 GMT+0100 (GMT Summer Time)] -> error