arrayify
Transform the given values into an array.
arrayify(val: any): array
Parameters
val
(any)
value
Returns
array
:
array
Example
var snu = require('s-node-utils');
snu.array.arrayify('abc');
//=> ['abc']
string
Determines if the string is a string.
Parameters
string
(string)
string
Returns
boolean
:
boolean
Example
var snu = require('s-node-utils');
snu.is.string('text');
//=> true
zalgo
Determines if the string consists of zalgo text.
Parameters
Returns
boolean
:
boolean
Example
var snu = require('s-node-utils');
snu.is.zalgo('ť͈̓̆h̏̔̐̑ì̭ͯ͞s̈́̄̑͋');
//=> true
int
Give a random number between 2 given numbers
Parameters
Returns
number
:
number
Example
var snu = require('s-node-utils');
snu.math.random.int(0, 5);
//=> 3
progressBar
Generate a progress bar
Parameters
percentage
(number
= 0
)
Percentage (out of 100)
totalSteps
(number
= 10
)
Number of characters
complete
(string
= "█"
)
Character (completed)
empty
(string
= "▒"
)
Character (empty)
Returns
string
:
bar
Example
var snu = require('s-node-utils');
snu.others.progressBar(5, 10);
//=> █████▒▒▒▒▒
snu.others.progressBar(44, 50, '!', '|');
//=> !!!!!!!!!!!!!!!!!!!!!!||||||||||||||||||||||||||||
generate
Generate a password
generate(length: number, lowercase: boolean, uppercase: boolean, numbers: boolean, symbols: boolean): string
Parameters
length
(number
= 5
)
Password length
lowercase
(boolean
= true
)
If password contain lowercases
uppercase
(boolean
= true
)
If password contain uppercases
numbers
(boolean
= true
)
If password contain numbers
symbols
(boolean
= false
)
If password contain symbols
Returns
string
:
Password
Example
var snu = require('s-node-utils');
snu.password.generate(50, true, true, false, true);
//=> Hnn}VnDySrnlJU.US>}vt<]|@)I^CB/.}|ehxFV_w%f;m,AlJA
hash
Hash a password
Parameters
Returns
string
:
Password
Example
var snu = require('s-node-utils');
snu.password.hash("F@3Ltv{>=q[8T%,", 10);
//=> $2a$10$OOJ2FlB56wSEhtwvVQxub.hoiWcEzcFsX2ERdNBo3fSXPSoSPK8zW (exemple)
capitalize
Converts the first string character to uppercase.
Parameters
string
(string)
Character string
Returns
string
:
Character string
Example
var snu = require('s-node-utils');
snu.string.capitalize('a text');
//=> A text
chop
Like trim.
Parameters
string
(string)
string
Returns
string
:
boolean
Example
var snu = require('s-node-utils');
snu.string.chop('text');
//=> text
snu.string.chop(' text ');
//=> text
snu.string.chop('-text-');
//=> text
shuffle
Mix characters in a string
Parameters
string
(string)
string
Returns
string
:
string
Example
ar snu = require('s-node-utils');
snu.string.shuffle("text");
//=> xtet
translate
Translation module
Parameters
string
(any)
options
(any)
Text
(string)
string
JSON
(object
= {to='en'}
)
Option (default: { from = 'auto', to = 'en', raw = false })
Returns
object
:
JSON (async function)
Example
var snu = require('s-node-utils');
(async () => {
console.log(
await snu.string.translate("Salut, comment sa va ?", { to: "en" })
);
})();
//=> { text: 'Hi, how are you?',
//=> from:
//=> { language: { didYouMean: false, iso: 'fr' },
//=> text:
//=> { autoCorrected: false,
//=> value: 'Salut, comment [ça] va ?',
//=> didYouMean: true } },
//=> raw: '' }
unzalgo
Removes all Zalgo text characters for every word in a string if the word is zalgo text.
Parameters
Returns
string
:
string
Example
var snu = require('s-node-utils');
snu.string.unzalgo('ť͈̓̆h̏̔̐̑ì̭ͯ͞s̈́̄̑͋');
//=> this
zalgolize
Transforms string to zalgo text.
Parameters
Returns
string
:
string
Example
var snu = require('s-node-utils');
snu.string.zalgolize('this');
//=> t̋hiͤsͮ