npm.io
1.0.2 • Published 2 years ago

craydent-utility

Licence
MIT
Version
1.0.2
Deps
29
Size
49 kB
Vulns
0
Weekly
0

Craydent 1.0.2

by Clark Inada

Craydent is all inclusive utility library. There are several ways to use the library in NodeJS. More detailed documentation on constants can be found at Craydent Properties. More detailed documentation on methods can be found at Craydent Methods

// require with prototypes - this require will add prototypes to extend classes and add two constants ($c, $g) to the global space.
// $g is an alias to global and $c is the constant containing all the utility methods and properties.
require('craydent-utility');
$c.logit($c.VERSION);
arr.prototypedMethod(args);
// require no conflict - this require is the fully modular version with no global constants, prototypes, or methods.
var $c = require('craydent-utility/noConflict');
$c.logit($c.VERSION);
$c.prototypedMethod(arr, args);
// require global - this require constants and methods in the global space and add prototypes to extend classes.
// $g is an alias to global and $c is the constant containing all the utility methods and properties.
require('craydent-utility/global');
logit($c.VERSION);
arr.prototypedMethod(args);

Categories

Constants

CONSOLE_COLORS (Object) LOCAL_IP (String) TEMPLATE_TAG_CONFIG (Object)
DEBUG_MODE (Boolean) MODULES_LOADED (Object) TEMPLATE_VARS (Array)
ERROR_TYPES (Array) PUBLIC_IP (String) VERSION (String)
HTTP_STATUS_TEMPLATE (Object) RESPONSES (Object)

Utility

catchAll

Info: Creates an catch all for exceptions in the current node service.

Return: (void)

Parameters:

  • callback: (ErrorCallback) Callback function to call when there is an uncaught exception
  • append?: (Boolean) Options to defer, ignore case, etc

Overloads:

None


zipit

Info: Download a zip of files from file contents

Return: (String)

Parameters:

  • files: (FileObject[]) Objects containing properties name for file name and content for file content

Overloads:

Parameters

  • filename: (String) Name of the file
  • content: (String) contents of the file

Methods

Utility


absolutePath

Info: Method to make retrieve the absolute path of the provided path

Return: (String)

Parameters:

  • path: (String) Path to convert to the absolute path

Overloads:

None


addObjectPrototype

Info: Method to extend the Object Class

Return: (void)

Parameters:

  • name: (String) name of the method to add
  • fn: (Function) method implementation
  • override?: (Bool) if true, override the previously defined prototype

Overloads:

None


ajax

Info: Method to make ajax calls

Return: (Promise)

Parameters:

  • url: (String) End point url
  • returnData?: (AjaxReturnType) Specifies which data to return when using Promise pattern

Overloads:

Parameters

  • params: (AjaxOptions) specs with common properties:
    (String) url
    (String) dataType
    (Mixed) hitch
    (Function[]) onerror
    (Function[])onsuccess
  • returnData?: (AjaxReturnType) Specifies which data to return when using Promise pattern

awaitable

Info: Makes a value awaitable via a Promise.

Return: (Promise)

Parameters:

  • value: (AwaitableValue) Value to make awaitable

Overloads:

Parameters

  • func: (Function) Function to make awaitable
  • context: (any) Context to use to execute func.

Parameters

  • func: (Function) Function to make awaitable
  • callbackIndex: (Integer) Index of callback argument.

Parameters

  • func: (Function) Function to make awaitable
  • context: (any) Context to use to execute func.
  • callbackIndex: (Integer) Index of callback argument.

Parameters

  • func: (Function) Function to make awaitable
  • context: (any) Context to use to execute func.
  • callbackIndex: (Integer) Index of callback argument.
  • returnIndex: (Integer) Index of callback argument.

clearCache

Info: Clear a module from the require cache.

Return: (Bool)

Parameters:

  • module?: (String) Single module to remove.

Overloads:

None


clusterit

Info: Enable clustering

Return: (void)

Parameters:

  • callback: (ClusterCallback) Method to call for Workers. Callback is passed the cluster object as an argument.

Overloads:

None


cout

Info: Log to console when DEBUG_MODE is true and when the console is available

Return: (void)

Parameters:

  • ...infinite: (any) any number of arguments can be passed.

Overloads:

None


cuid

Info: Creates a Craydent/Global Unique Identifier

Return: (String)

Parameters:

  • msFormat?: (Bool) use microsoft format if true

Overloads:

None


exclude

Info: Exclude prototyping

Return: (void)

Parameters:

  • list: (String[]) Array of strings in containing the property to exclude from prototyping.

Overloads:

None


foo

Info: Place holder function for a blank function

Return: (void)

Parameters:

None

Overloads:

None


include

Info: Require without erroring when module does not exist.

Return: (any|false)

Parameters:

  • path: (String) Module or Path to module.
  • refresh?: (Bool) Flag to clear cache for the specific include.

Overloads:

None


isNull

Info: Check if a value is Null

Return: (Bool|any)

Parameters:

  • value: (any) Value to check

Overloads:

Parameters

  • value: (any) Value to check
  • defaultValue: (any) Value to return if null

logit

Info: Log to console when DEBUG_MODE is true and when the console is available

Return: (void)

Parameters:

  • ...infinite: (any) any number of arguments can be passed.

Overloads:

None


md5

Info: MD5 encode a string.

Return: (String)

Parameters:

  • str: (String) String to encode.

Overloads:

None


mkdirRecursive

Info: Recursively create folders.

Return: (void)

Parameters:

  • path: (String) Path to create.
  • callback: (Function) Method to call when directories are created (Gets passed error object as an argument and is null if there were no errors).

Overloads:

None


namespace

Info: Adds the class to a namespace instead of the global space

Return: (void)

Parameters:

  • name: (String) Name of the namespace to add to.
  • clazz: (Class) Class to add to the given namespace
  • fn: (Function) Method to call after the class has been added to the namespace

Overloads:

None


noop

Info: Place holder function for a blank function

Return: (void)

Parameters:

None

Overloads:

None


now

Info: Get the DateTime of now

Return: (Date|String)

Parameters:

  • format?: (String) Format syntax to return formatted string of now

Overloads:

None


parseBoolean

Info: Try to parse value to a Boolean (0, 1, '0', and '1' are valid unless strict is set to true).

Return: (Bool|undefined)

Parameters:

  • value: (any) value to parse as boolean.
  • strict?: (Boolean) Disable parsing of 0, 1, '0', and '1'.

Overloads:

None


parseRaw

Info: Creates an evaluable string

Return: (String)

Parameters:

  • value: (any) value to parse
  • skipQuotes?: (Bool) Flag to skip quotes for strings
  • saveCircular?: (Bool) Flag to save circular references

Overloads:

None


rand

Info: Create a random number between two numbers

Return: (Number)

Parameters:

  • num?1: (Number) Lower bound
  • num2?: (Number) Upper bound
  • inclusive?: (Bool) Flag to include the given numbers

Overloads:

None


requireDirectory

Info: Recursively require the entire directory and returns an object containing the required modules.

Return: (Promise|any)

Parameters:

  • path: (String) Path to directory.
  • options?: (Char) 'r' Flag to use to indicate recursively require, (Char) 's' Flag to indicate use syncronous instead of Promise Pattern

Overloads:

None


runFuncArray

Info: Executes array of methods

Return: (Bool)

Parameters:

  • funcs: (Function[]) Array of methods to execute
  • args: (any[]) Array of arguments to be passed to each method

Overloads:

None


suid

Info: Creates a short Craydent/Global Unique Identifier

Return: (String)

Parameters:

  • length?: (Integer) Custom length of the short unique identifier. Default is 10.

Overloads:

None


syncroit

Info: Generator/Async based control flow to allow for more "syncronous" programing structure

Return: (Promise)

Parameters:

  • func: (GeneratorFunction|AsyncFunction) function to execute

Overloads:

None


tryEval

Info: Evaluates an expression without throwing an error

Return: (any)

Parameters:

  • expression: (any) Expression to evaluate
  • evaluator?: (EvaluatorMethod) Method to use to evaluate the expression

Overloads:

None


wait

Info: Stops execution until the condition is satisfied

Return: (void)

Parameters:

  • condition: (Code) Condition equivalent to js true to resume execution

Overloads:

None


yieldable

Info: Makes a value yieldable via a Promise.

Return: (Promise)

Parameters:

  • value: (YieldableValue) Value to make yieldable

Overloads:

Parameters

  • func: (Function) Function to make yieldable
  • context: (any) Context to use to execute func.

Parameters

  • func: (Function) Function to make yieldable
  • callbackIndex: (Integer) Index of callback argument.

Parameters

  • func: (Function) Function to make yieldable
  • context: (any) Context to use to execute func.
  • callbackIndex: (Integer) Index of callback argument.

Parameters

  • func: (Function) Function to make yieldable
  • context: (any) Context to use to execute func.
  • callbackIndex: (Integer) Index of callback argument.
  • returnIndex: (Integer) Index of callback argument.

Download

Keywords