New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

bareutil

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bareutil

Yet another utility library

latest
Source
npmnpm
Version
1.5.4
Version published
Weekly downloads
8
-78.38%
Maintainers
1
Weekly downloads
 
Created
Source

bareutil

Yet Another Javascript Utility library

Contains recurring goto methods I encounter during development If you come across any problems, please create an issue

How to use

var bare = require("bareutil");
var misc = bare.misc;
var obj = bare.obj;
var val = bare.val;

//Expose to client *.com/bare.misc.js using express
var express = require('express');
var app = express();

bare.misc.expose(app, express);
bare.obj.expose(app, express);
bare.val.expose(app, express);

How to run tests

cd bareutil
npm run test
npm run coverage

Validation (bare.val)

All validation is done by performing a check on the object's constructor

  • bare.val.undefined(obj) - var obj; is true
  • defined(obj) - var obj; is false
  • function(obj) - function() { } is true
  • object(obj) - { } is true
  • number(obj) - 12 is true
  • string(obj) - "Hello" is true
  • date(obj) - new Date() is true
  • boolean(obj) - false is true
  • regex(obj) - \(w*)\g is true
  • promise(obj) - new Promise() is true

Object (bare.obj)

Functional programming for objects

Array-like methods have 2 required and 1 optional parameter:

  • obj - The object to perform the operation on
  • cb(key, value) - Function called for each element in the object
  • allowFuncs - Will include functions in iterations
Array-like - function(obj, cb, allowFuncs)
  • bare.obj.find - Returns value if a match is found Performs a strict comparison when a non-function is provided
  • each - Executes cb once per property
  • map - Performs transformation on object's values. Keys are preserved.
  • reduce - Provides an accumulator to reduce object down to a single value cb(accumulated, value, key)
  • filter - Constructs new object from calls that return true. Keys are preserved.
  • keys - An array of the keys of the object
  • values - An array of the values of the object
  • toArray - Transforms into an array of {key, value} pairs
  • sum - Reduces by adding. Return true/false from cb to sum value
Other
  • bare.obj.increment(obj, map) - Increment each matching key by value
  • write(obj, data) - Assigns all key/values from data to obj
  • merge(obj, data) - Assigns all matching key/values from data to obj
  • slim(obj, prop) - Flattens a nested object by the property
  • copy(obj) - Creates a shallow copy the object
  • has(obj, prop) - true if object has that property defined
  • contains(obj, coll) - true if obj shares all keys with coll

Misc (bare.misc)

  • bare.misc.supplant(str, values) - String substitution, {key} or $key syntax
  • random(length, possible) - Random string from possible characters
  • once(fn, context) - Calls functions with context only once. Subsequent calls return result
  • throwLater(err, msg) - Throws error sometime later
  • throwWith(msg) - Returns throw later function with msg prepended

Ajax (bare.ajax)

    Not available for server-side yet, hasn't been tested. Don't use it

Keywords

bare

FAQs

Package last updated on 22 Aug 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