Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

core-functions

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-functions

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.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
62
increased by26.53%
Maintainers
1
Weekly downloads
 
Created
Source

core-functions v2.0.0

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:

  • app-errors.js - a collection of standard application AppError subclasses for the more commonly used HTTP status codes
  • arrays.js - Array utilities
  • base64.js - utilities for encoding from UTF-8 to Base 64 and vice-versa
  • booleans.js - boolean utilities
  • numbers.js - number utilities
  • objects.js - Object utilities
  • promises.js - native Promise utilities
  • strings.js - string utilities
  • timers.js - Timer/timeout utilities

This module is exported as a Node.js module.

Installation

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('../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;

Unit tests

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.

Changes

1.1.0

  • strings: Added trimOrEmpty function
  • strings: Renamed safeTrim function to trim and changed safeTrim to an alias for trim

1.1.1

  • Simple increment of version number to fix issue of 1.1.0 tag pointing to wrong version

1.2.0

  • strings:
    • Improvements to stringify function to better handle functions and arrays
  • promises:
    • Added isPromise function
    • Added optional cancellable argument to delay function to enable cancellation of delay's timeout
  • Added new modules:
    • app-errors
    • arrays
    • objects
    • timers
  • Added unit tests for existing and new functions and classes.

2.0.0

  • Removed unnecessary functions.js module
  • Patches to testing.js checkMethodEqual and checkMethodOkNotOk functions to show method prefixes properly

FAQs

Package last updated on 03 Nov 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc