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.11 to 0.0.12

test/curry.js

6

lib/cache.js

@@ -7,3 +7,3 @@ 'use strict';

// Extend Map interface total allocated size: map.allocated
options
options // { calcSize }
) => {

@@ -29,3 +29,3 @@ const cache = new Map();

prefix, // string to compare with key start
fn //
fn // listener function `(key)` on delete key
) => {

@@ -69,3 +69,3 @@ let key;

prefix, // string to compare with key start
fn // function(key, val) to be called on each key (optional)
fn // function `(key, val)` to be called on each key (optional)
) => {

@@ -72,0 +72,0 @@ cache.forEach((val, key) => {

@@ -10,4 +10,4 @@ 'use strict';

api.common.copy = (
// Copy dataset (copy objects to new array)
ds
// Copy dataset, copy objects to new array
ds // array, source dataset
) => ds.slice();

@@ -26,3 +26,6 @@ /* TODO: test speed in following implementations:

api.common.clone = (obj) => {
api.common.clone = (
// Clone object
obj // object or array
) => {
if (typeof(obj) !== 'object' || obj === null) return obj;

@@ -68,3 +71,6 @@ return Array.isArray(obj) ? cloneArray(obj) : cloneObject(obj);

api.common.duplucate = (obj) => {
api.common.duplucate = (
// Duplicate object
obj // object or array
) => {
if (typeof(obj) !== 'object' || obj === null) return obj;

@@ -121,4 +127,5 @@ const references = new Map();

api.common.getByPath = (
data, // data - object/hash
dataPath // string in dot-separated path
// Read property by dot-separated path
data, // object
dataPath // string, dot-separated path
) => {

@@ -138,5 +145,6 @@ const path = dataPath.split('.');

api.common.setByPath = (
data, // object/hash
dataPath, // string in dot-separated path
value // value to be assigned
// Set property by dot-separated path
data, // object
dataPath, // string, dot-separated path
value // new value
) => {

@@ -165,4 +173,5 @@ const path = dataPath.split('.');

api.common.deleteByPath = (
data, // object/hash
dataPath // string in dot-separated path
// Delete property by dot-separated path
data, // object
dataPath // string, dot-separated path
) => {

@@ -188,3 +197,6 @@ const path = dataPath.split('.');

api.common.merge = (...args) => {
api.common.merge = (
// Distinct merge miltiple arrays
...args // arrays
) => {
const array = args[0];

@@ -191,0 +203,0 @@ let i, ilen, j, jlen, arr, val;

@@ -5,4 +5,2 @@ 'use strict';

api.common.curry = (fn, ...args) => fn.bind(null, ...args);
api.common.omap = (

@@ -21,3 +19,8 @@ // Function for mapping object fields

api.common.compose = (...fns) => (...args) => {
api.common.compose = (
// Compose functions
...fns // functions
) => (
...args // arguments to bassed to first function
) => {
if (fns.length === 0) return args[0];

@@ -38,9 +41,9 @@

api.common.zip = (
// Zipping several arrays into one.
// Zipping several arrays into one
...arrays // input arrays
// Returns array length is minimal of input arrays length
// Element with index i of resulting array is array with
// elements with index i from input arrays.
// elements with index i from input arrays
) => {
if (arrays.length === 0) return [];
if (arrays.length === 0) return arrays;
let i, j;

@@ -63,10 +66,6 @@

api.common.replicate = (count, elem) => {
const res = new Array(count);
let i;
for (i = 0; i < count; i++) {
res[i] = elem;
}
return res;
};
api.common.replicate = (count, elem) => Array.from(
{ length: count },
() => elem
);

@@ -91,3 +90,3 @@ api.common.zipWith = (

fn, // function which will be curried
...args1 // arguments for fn
...args // arguments for fn
// Returns curried function

@@ -106,3 +105,3 @@ ) => {

return curryMore(...args1);
return curryMore(...args);
};

@@ -115,3 +114,3 @@

count, // number of times function should be curried
...args1 // arguments for first currying
...args // arguments for first currying
// Returns curried count times function

@@ -121,3 +120,3 @@ ) => {

const condition = () => (i++, i === count);
return api.common.curryUntil(condition, fn, ...args1);
return api.common.curryUntil(condition, fn, ...args);
};

@@ -127,4 +126,7 @@

api.common.fullCurry = (fn, ...args1) => {
api.common.curry = (
// Curry function
fn, // function
...args // arguments
) => {
let argsTotalCount = 0;

@@ -135,3 +137,3 @@ const condition = (argsI) => (

);
return api.common.curryUntil(condition, fn, ...args1);
return api.common.curryUntil(condition, fn, ...args);
};

@@ -141,3 +143,8 @@

api.common.either = (fn) => (...args) => {
api.common.either = (
// Return first not errored result of fn
fn // function to be called
) => (
...args // arguments to iterate
) => {
let arg;

@@ -144,0 +151,0 @@ let lastError;

@@ -92,2 +92,3 @@ 'use strict';

api.common.validateSID = (
// Validate SID
config, // { length, characters, secret }

@@ -94,0 +95,0 @@ sid // session id string

@@ -12,2 +12,3 @@ 'use strict';

callback // function (optional)
// Returns wrapped callback
) => {

@@ -20,3 +21,3 @@ let done = false;

};
return callback ? wrap : api.common.falseness;
return callback ? wrap : api.common.emptiness;
};

@@ -31,14 +32,14 @@

) => {
const lastArg = args[args.length - 1];
if (typeof(lastArg) !== 'function') return api.common.falseness;
const callback = args[args.length - 1];
if (typeof(callback) !== 'function') return api.common.emptiness;
const cb = api.common.cb(lastArg);
args.pop();
return api.common.cb(cb);
return api.common.cb(callback);
};
api.common.override = (
obj, // object containing function to override
fn // function, name will be used to find function inside object
// Hint: previous function will be accessible by obj.fnName.inherited
// Override method: save old to `fn.inherited`
obj, // object containing method to override
fn // function, name will be used to find method
// Previous function will be accessible by obj.fnName.inherited
) => {

@@ -50,4 +51,5 @@ fn.inherited = obj[fn.name];

api.common.range = (
from, // sequence start
to // sequence end
// Generate int array from given range
from, // range start
to // range end
// Example: range(1, 5) = [1, 2, 3, 4, 5]

@@ -66,2 +68,3 @@ ) => {

api.common.sequence = (
// Generate int array from sequence syntax
seq, // array

@@ -88,3 +91,7 @@ max // optional max

api.common.random = (min, max) => {
api.common.random = (
// Generate random int in given range
min, // range start
max // range end
) => {
if (max === undefined) {

@@ -97,7 +104,12 @@ max = min;

api.common.shuffle = (arr) => (
api.common.shuffle = (
// Shuffle an array
arr // array
) => (
arr.sort(() => Math.random() - 0.5)
);
api.common.eventEmitter = () => {
api.common.eventEmitter = (
// EventEmitter with wildcard
) => {
const ee = new api.events.EventEmitter();

@@ -115,6 +127,4 @@ const emit = ee.emit;

api.common.restLeft = (
// Transforms function with (args, arg1 .. argN, callback) arguments
// to function with (arg1 .. argN, ...args, callback) arguments
fn // transforming function
// Returns transformed function
// Rest left, transfor function
fn // (args, arg1..argN, callback) to (arg1..argN, ...args, callback)
) => (...spreadArgs) => {

@@ -121,0 +131,0 @@ const callback = api.common.cbExtract(spreadArgs);

@@ -5,7 +5,13 @@ 'use strict';

api.common.ip2int = (ip = '127.0.0.1') => (
api.common.ip2int = (
// Pack IP string to single int
ip = '127.0.0.1'
) => (
ip.split('.').reduce((res, item) => (res << 8) + (+item), 0)
);
api.common.localIPs = () => {
api.common.localIPs = (
// Get local network interfaces
// Returns array of strings
) => {
let ips = api.common.localIPs.cache;

@@ -30,4 +36,5 @@ if (ips) return ips;

api.common.parseHost = (
// Parse host string
host // host or empty string, may contain :port
// Return: host without port but not empty
// Returns host without port but not empty
) => {

@@ -34,0 +41,0 @@ if (!host) host = 'no-host-name-in-http-headers';

@@ -6,4 +6,5 @@ 'use strict';

api.common.sortComparePriority = (
priority, // array of strings with priority order
s1, s2 // config files names to sort in required order
// Compare for array.sort with priority
priority, // array of strings with priority
s1, s2 // comparing strings
// Example:

@@ -23,3 +24,4 @@ // comp = api.common.sortComparePriority(impress.CONFIG_FILES_PRIORITY);

api.common.sortCompareDirectories = (
a, b // strings to compare
// Compare for array.sort, directories first
a, b // comparing strings
// Example: files.sort(api.common.sortCompareDirectories);

@@ -37,3 +39,4 @@ ) => {

api.common.sortCompareByName = (
a, b // objects to compare
// Compare for array.sort
a, b // objects `{ name }` to compare
// Example: files.sort(api.common.sortCompareByName);

@@ -40,0 +43,0 @@ ) => {

@@ -13,3 +13,3 @@ 'use strict';

escapeHtml // escape html special characters if true
// Return: string
// Returns string
) => (

@@ -51,2 +51,3 @@ tpl.replace(SUBST_REGEXP, (s, key) => {

api.common.htmlEscape = (
// Escape html characters
content // string to escape

@@ -59,5 +60,6 @@ // Example: api.common.htmlEscape('5>=5') : '5&lt;=5'

api.common.fileExt = (
fileName // extract file extension in lower case with no dot
// Extract file extension in lower case with no dot
fileName // string, file name
// Example: api.common.fileExt('/dir/file.txt')
// Return: 'txt'
// Result: 'txt'
) => (

@@ -68,5 +70,6 @@ api.path.extname(fileName).replace('.', '').toLowerCase()

api.common.removeExt = (
fileName // remove ext from fileName
// Remove file extension from file name
fileName // string, file name
// Example: api.common.fileExt('file.txt')
// Return: 'file'
// Result: 'file'
) => (

@@ -79,3 +82,4 @@ fileName.substr(0, fileName.lastIndexOf('.'))

api.common.spinalToCamel = (
name // convert spinal case to camel case
// convert spinal case to camel case
name // string
) => (

@@ -101,3 +105,5 @@ name

api.common.escapeRegExp = (
s // escapeRegExp('/path/to/res?search=this.that')
// Escape regular expression control characters
s // string
// Example: escapeRegExp('/path/to/res?search=this.that')
) => (

@@ -107,3 +113,7 @@ s.replace(ESCAPE_REGEXP, '\\$&')

api.common.newEscapedRegExp = (s) => (
api.common.newEscapedRegExp = (
// Generate escaped regular expression
s // string
// Returns: instance of RegExp
) => (
new RegExp(api.common.escapeRegExp(s), 'g')

@@ -114,7 +124,13 @@ );

api.common.stripTrailingSlash = (s) => (
api.common.stripTrailingSlash = (
// Remove trailing slash from string
s // string
) => (
s.endsWith('/') ? s.substr(0, s.length - 1) : s
);
api.common.dirname = (path) => {
api.common.dirname = (
// Get directory name with trailing slash from path
path // string
) => {
let dir = api.path.dirname(path);

@@ -127,3 +143,6 @@ if (dir !== '/') dir += '/';

api.common.capitalize = (s) => (
api.common.capitalize = (
// Capitalize string
s // string
) => (
s.replace(CAPITALIZE_REGEXP, (word) => (

@@ -135,3 +154,4 @@ word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()

api.common.between = (
s, // string to extract substring between prefix and suffix
// Extract substring between prefix and suffix
s, // source string
prefix, // substring before needed fragment

@@ -154,3 +174,4 @@ suffix // substring after needed fragment

api.common.removeBOM = (
s // string possibly starts with UTF-8 BOM
// Remove UTF-8 BOM
s // string possibly starts with BOM
) => (

@@ -163,3 +184,4 @@ typeof(s) === 'string' ? s.replace(BOM_REGEXP, '') : s

api.common.arrayRegExp = (
items // array of strings with '*' wildcards to be converted into one RegExp
// Generate RegExp from array with '*' wildcards
items // array of strings
// Example: ['/css/*', '/index.html']

@@ -166,0 +188,0 @@ ) => {

@@ -6,8 +6,9 @@ 'use strict';

api.common.isTimeEqual = (
time1, // Compare time1
time2 // and time2 in milliseconds
// Compare time1 and time2
time1, // time string or milliseconds
time2 // time string or milliseconds
// Example: api.common.isTimeEqual(sinceTime, buffer.stats.mtime);
// Return: boolean
// Result: boolean
) => (
new Date(time2).getTime() === new Date(time1).getTime()
new Date(time1).getTime() === new Date(time2).getTime()
);

@@ -18,3 +19,5 @@

api.common.nowDate = (
now // date object (optional) to YYYY-MM-DD
// Current date in YYYY-MM-DD format
now // date object (optional)
// Returns string
) => {

@@ -30,3 +33,5 @@ if (!now) now = new Date();

api.common.nowDateTime = (
now // date object (optional) to YYYY-MM-DD hh:mm
// Current date in YYYY-MM-DD hh:mm format
now // date object (optional)
// Returns string
) => {

@@ -33,0 +38,0 @@ if (!now) now = new Date();

@@ -13,4 +13,6 @@ 'use strict';

api.common.duration = (
s // parse duration to seconds
// Parse duration to seconds
s // string in duration syntax
// Example: duration('1d 10h 7m 13s')
// Returns milliseconds
) => {

@@ -31,3 +33,4 @@ if (typeof(s) === 'number') return s;

api.common.bytesToSize = (
bytes // number to be converted to size Kb, Mb, Gb and Tb
// Convert int to string size Kb, Mb, Gb and Tb
bytes // int size
) => {

@@ -47,3 +50,4 @@ if (bytes === 0) return '0';

api.common.sizeToBytes = (
size // string with units to be converted to number
// Convert string with units to int
size // string size
) => {

@@ -50,0 +54,0 @@ if (typeof(size) === 'number') return size;

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

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

"scripts": {
"test": "node tests/examples.js && tap test/*.js && npm run lint",
"test": "tap test/*.js && npm run lint",
"code-coverage": "tap test/*.js --100",

@@ -25,0 +25,0 @@ "code-coverage-report": "tap test/*.js --coverage-report=html",

@@ -24,4 +24,4 @@ 'use strict';

test.strictSame(args, expectedArgs);
test.strictSame(wrappedCb, common.falseness);
test.strictSame(wrappedCb, common.emptiness);
test.end();
});
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