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

metarhia-common

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metarhia-common - npm Package Compare versions

Comparing version 0.0.20 to 0.0.21

lib/utilities.js

1

common.js
'use strict';
const submodules = [
'utilities', // Common utilities
'math', // Math common function

@@ -5,0 +6,0 @@ 'array', // Arrays manipulations

60

lib/callbacks.js
'use strict';
const { last } = require('./array');
const { alias } = require('./utilities');
const falseness = (

@@ -33,8 +36,8 @@ // Empy function

const cb = (
// Wrap callback: call once, not null
callback // function (optional)
const once = (
// Wrap function: call once, not null
fn // function (optional)
// Returns: function, wrapped callback
) => {
if (!callback) return emptiness;
if (!fn) return emptiness;
let finished = false;

@@ -44,3 +47,3 @@ const wrap = (...args) => {

finished = true;
callback(...args);
fn(...args);
};

@@ -50,26 +53,26 @@ return wrap;

const cbUnsafe = (
// Exctracts callback
// callback is last argument
const unsafeCallback = (
// Extract callback function
// It's unsafe: may return null, allow multiple calls
args // array, arguments
// Returns: function, callback
// Returns: function, callback or null
// Hint: previous name: `common.cbUnsafe` (deprecated)
// Hint: another alias: `common.extractCallback` (deprecated)
) => {
const callback = args[args.length - 1];
if (typeof(callback) !== 'function') return;
args.pop();
return callback;
const callback = last(args);
if (typeof(callback) === 'function') return args.pop();
return null;
};
const cbExtract = (
// Exctracts callback and wraps it with common.cb
// callback is last argument otherwise returns common.falseness
const safeCallback = (
// Exctracts callback and make it safe
// Wrap collback with once
// and return common.emptiness if no callback
args // array, arguments
// Returns: function, wrapped callback
// Hint: previous name: `cbExtract` (deprecated)
) => {
const callback = args[args.length - 1];
if (typeof(callback) !== 'function') return emptiness;
args.pop();
return cb(callback);
const callback = last(args);
if (typeof(callback) === 'function') return once(args.pop());
return emptiness;
};

@@ -83,5 +86,12 @@

noop,
cb,
cbUnsafe,
cbExtract,
once,
cb: alias(once),
unsafeCallback,
extractCallback: alias(unsafeCallback),
cbUnsafe: alias(unsafeCallback),
safeCallback,
cbExtract: alias(safeCallback),
};
'use strict';
const { cbExtract } = require('./callbacks');
const { safeCallback } = require('./callbacks');

@@ -170,3 +170,3 @@ const omap = (

) => (...spreadArgs) => {
const callback = cbExtract(spreadArgs);
const callback = safeCallback(spreadArgs);
const namedArgsCount = fn.length - 2;

@@ -173,0 +173,0 @@ const namedArgs = spreadArgs.slice(0, namedArgsCount);

{
"name": "metarhia-common",
"version": "0.0.20",
"version": "0.0.21",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -32,3 +32,3 @@ "description": "Metarhia Common Library",

"devDependencies": {
"metaschema": "^0.0.4",
"metaschema": "^0.0.5",
"eslint": "^4.3.0",

@@ -35,0 +35,0 @@ "tap": "^10.7.0"

@@ -307,18 +307,24 @@ # Metarhia Common Library

### Wrap callback: call once, not null
`common.cb(callback)`
- `callback:function` (optional)
### Wrap function: call once, not null
`common.once(fn)`
- `fn:function (optional)`
Returns: function, wrapped callback
### Exctracts callback
`common.cbUnsafe(callback, args)`
- `callback` - is last argument
Hint: previous name: `common.cb` (deprecated)
### Extract callback function
It's unsafe: may return null, allow multiple calls
`common.unsafeCallback(args)`
- `args:array` - arguments
Returns: function, callback
Returns: function, callback or null
### Exctracts callback and wraps it with common.cb
`common.cbExtract(args)
callback is last argument, otherwise it's common.falseness, args
Hint: previous name: `common.cbUnsafe` (deprecated)
Hint: another alias: `common.extractCallback` (deprecated)
### Exctracts callback and make it safe
Wrap collback with once and return common.emptiness if no callback
`common.safeCallback(args)`
- `args:array` - arguments

@@ -328,2 +334,4 @@

Hint: previous name: `cbExtract` (deprecated)
### Override method: save old to `fn.inherited`

@@ -330,0 +338,0 @@ `common.override(obj, fn, Hint)`

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