Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
core-functions
Advanced tools
Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.
Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.
Currently includes:
This module is exported as a Node.js module.
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save core-functions
In Node.js:
To use the string utilities
const Strings = require('core-functions/strings');
To use the number utilities
const Numbers = require('core-functions/numbers');
To use the boolean utilities
const Booleans = require('core-functions/booleans');
To use the Base 64 encoding and decoding utilities
const base64 = require('core-functions/base64');
To use the Promise utilities (as static methods on the native Promise
class)
require('core-functions/promises');
To use the Promise utilities (as exported functions)
const promises = require('core-functions/promises');
To use the Object utilities
const Objects = require('core-functions/objects');
To use the Array utilities
const Arrays = require('core-functions/arrays');
To use the Timer utilities
const timers = require('core-functions/timers');
To use the standard application errors
const appErrors = require('core-functions/app-errors');
const AppError = appErrors.AppError;
// 400-series
const BadRequest = appErrors.BadRequest;
const Unauthorized = appErrors.Unauthorized;
const Forbidden = appErrors.Forbidden;
const NotFound = appErrors.NotFound;
const RequestTimeout = appErrors.RequestTimeout;
const TooManyRequests = appErrors.TooManyRequests;
// 500-series
const InternalServerError = appErrors.InternalServerError;
const BadGateway = appErrors.BadGateway;
const ServiceUnavailable = appErrors.ServiceUnavailable;
const GatewayTimeout = appErrors.GatewayTimeout;
// HTTP status codes with explicit class support and allowed to pass through to API Gateway by default
const supportedHttpStatusCodes = appErrors.supportedHttpStatusCodes;
// Error conversion functions
const toAppError = appErrors.toAppError;
const toAppErrorForApiGateway = appErrors.toAppErrorForApiGateway;
This module's unit tests were developed with and must be run with tape. The unit tests have been tested on Node.js v4.3.2.
See the package source for more details.
errors
module from version 3.0.10objects
module copy
function fix for TypeError thrown when Object.create(o.__proto__)
was invoked & o.__proto__
was undefinedstrings.test.js
equality failure that surfaces when run under Node 6.10.xcopyNamedProperties
function to objects.js
modulegetPropertyValue
function to objects.js
moduleapp-errors.js
module to export getHttpStatus
functionapp-errors.js
module's AppError
constructor:
objects.js
module's copy
and merge
functions:
strings.js
module's stringify
function:
toString
methods, with square brackets (to indicate
that the property does not contain just a string error message)strings.js
module's stringify
function:
toJSON
methods (if any) by default (prior versions did NOT use them at all)avoidToJSONMethods
argument to determine whether to avoid using objects' toJSON methods or not (default)JSON.stringify
name
as the first property, followed by its message
as the second property, followed by the rest of its
enumerable properties (excluding its stack
property)[Reference: {name}]
, whereas the prior version marked them incorrectly as [Circular: {name}]
[Circular: {name}]
strings.js
module's stringify
function:
JSON.stringify
useToStringForErrors
argument to convert Errors using their toString
methods (if true) or
as objects (if false), but with their message
and name
(but not stack
) properties visible in the resultquoteStrings
argument to return given string values surrounded with double-quotes (if true)objects.js
:
merge
functionobjects.js
:
merge
function to handle circular, non-Directed Acyclic Graphs of objectscopy
function also able to handle non-DAGsobjects.js
:
merge
functionstrings.js
:
nthIndexOf
function that finds index of nth occurrence of a search value in a stringpromises.js
:
every
function that accepts multiple promises and returns a single promise that returns a list of either a result or an error for each and every one of the given promisespromises.js
:
isPromise
to survive undefined and nullisArrayOfPromises
function to check if a result is an array of promisesallOrOne
function to transform a result into a single promise
using Promise.all
, the promise-result or Promise.resolve
Promise.try
to use new Promise.allOrOne
allOrOne
& isArrayOfPromises
and more tests for try
x instanceof Array
checks with safer Array.isArray(x)
checkMethodEqual
and checkMethodOkNotOk
functions to show method prefixes properlystringify
function to better handle functions and arraysisPromise
functioncancellable
argument to delay
function to enable cancellation of delay's timeouttrimOrEmpty
functionsafeTrim
function to trim
and changed safeTrim
to an alias for trim
FAQs
Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.
The npm package core-functions receives a total of 48 weekly downloads. As such, core-functions popularity was classified as not popular.
We found that core-functions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.