Module: cpb-common

Common (shared) functions

Source:

Members

(static, constant) attachProcessHandlers

ATTACHES EXCEPTIONS HANDLERS TO THE CURRENT NODE PROCESS

Source:

(static, constant) isIterable

checks for Iterability

Source:

(static, constant) lowercaseProperties

converts all project attributes to lowercase values

Source:

(static, constant) makeChunks

Split source array into chunks

Source:

(static, constant) randomNumber

Pseudo-random number generator

Source:

(static, constant) release :string

APP RELEASE VERSION

Type:
  • string
Source:

(static, constant) timestamp

Get current timestamp in YYMMDDHMSS format

Source:

Methods

(static) createQueryFilter(filterObject) → {Array(string, unknown)}

Create Datastore Query Filter Array from Object

Parameters:
Name Type Description
filterObject object
Source:
Returns:
Type
Array(string, unknown)

(static) error()

LOGS ALL SUPPLIED ARGUMENTS AS ERROR IN FORMATTED JSON

Source:

(static) getBinaryFlagValue(f, defaultValueopt) → {boolean}

cast string or integer values to boolean

Parameters:
Name Type Attributes Default Description
f *

value to convert

defaultValue boolean | number <optional>
0

default value

Source:
Returns:
Type
boolean

(static) getRelease() → {string}

Get current app release:version

Source:
Returns:

[release= `${process.env.npm_package_name}:${process.env.npm_package_version}'] - release info

Type
string

(static) hasTrailingSlash(str) → {boolean}

check if the last character of string is the forward slash '/'

Parameters:
Name Type Description
str string | *
Source:
Returns:
Type
boolean

(static) inspect(nlopt, nullable, outopt, nullable, optionsopt, nullable) → {string}

util.inspect settings for printing deep json structures

Parameters:
Name Type Attributes Default Description
nl string <optional>
<nullable>
'\n'

new line ending character

out Array() <optional>
<nullable>
[]

shared output array

options object <optional>
<nullable>

util.inspect.options

Properties
Name Type Attributes Default Description
depth number <optional>
6
colors boolean <optional>
true
sorted boolean <optional>
true
getters boolean <optional>
true
compact boolean <optional>
true
showHidden boolean <optional>
true
Source:
Returns:

result - text for outputting

Type
string

(static) isArray(obj) → {boolean}

check whether the given param is an array

Parameters:
Name Type Description
obj *
Source:
Returns:
Type
boolean

(static) isDebug() → {boolean}

true if debug mode enabled

Source:
Returns:

isDebug

Type
boolean

(static) isObject(obj) → {boolean}

Check if Object

Parameters:
Name Type Description
obj *

anything

Source:
Returns:

isObject - true if object; false otherwise

Type
boolean

(static) isTrue(d) → {boolean}

evaluate to boolean true value

Parameters:
Name Type Description
d *
Source:
Returns:
Type
boolean

(static) line() → {string}

GENERATE DELIMITER LINE

Properties:
Name Type Description
prop.char string

char for line

prop.length number

line length

prop.breaks number | string

end of line breaks count

Source:
Returns:

line - delimiter line

Type
string
Example
line();                                                       //
  =>'\n------------------------------------------------------------\n' line({chr:'+', length:10});
           // => '\n++++++++++\n' line({chr:'>+', length:10, breaks: 5});    // =>
  '\n\n\n\n\n>+>+>+>+>+>+>+>+>+>+\n\n\n\n\n'

(static) parseJSONL(fileName, nameopt, generateImportedAtopt, generateUuidopt, generateUuidExclude) → {Array.<object>}

parse JSONL from the local file

Parameters:
Name Type Attributes Default Description
fileName string

name of the file to parse data from

name string <optional>
fileName

filename

generateImportedAt boolean <optional>
true

add DATETIME::IMPORTED_AT to the record

generateUuid boolean <optional>
true

add uuidv5::uuid to the record based upon object data

generateUuidExclude Array.<string>

list of attributes to be excluded from uuid hashing

Source:
Returns:
Type
Array.<object>

(static) removeTrailingSlash(str) → {string|*}

remove last character from string if it is a forward slash

Parameters:
Name Type Description
str string
Source:
Returns:

str - chopped string

Type
string | *

(static) sortObjectAttributes(onon-null, reverseopt, nullable) → {object}

Sort object attributes alphabetically Ascending

Parameters:
Name Type Attributes Description
o object

object to sort

reverse * <optional>
<nullable>

reverse the sort order

Source:
Returns:

sorted - new sorted object

Type
object

(static) stringifyJSON(data, canonicalopt, nullable, indentopt, nullable) → {*}

EJSON Stringify Object

Parameters:
Name Type Attributes Default Description
data object | *
canonical boolean <optional>
<nullable>
true
indent number <optional>
<nullable>
0

formatter indent. Defaults to no indents (one object per line)

Source:
Returns:
Type
*

(static) title()

Prints Message with Formatting

Source:

(static) toJSONL(d) → {string}

Convert data to JSONL string

Parameters:
Name Type Description
d object | string | Array.<(object|string)>
Source:
Returns:

JSONL - JSONL formatted output

Type
string

(static) uniq() → {Array.<string>}

Get unique array values

Source:
Returns:
Type
Array.<string>
Example
uniq(1,2,3,2,2,2) // [ '1', '2', '3' ]