sling-web-helpers
Advanced tools
Comparing version 0.6.0 to 0.8.0
@@ -6,2 +6,13 @@ 'use strict'; | ||
}); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var isString = exports.isString = function isString(arg) { | ||
@@ -32,2 +43,85 @@ return typeof arg === 'string' || arg instanceof String; | ||
return startDate !== finalDate; | ||
}; | ||
var toFlatArray = exports.toFlatArray = function toFlatArray(result, arg) { | ||
return Array.isArray(arg) ? [].concat(_toConsumableArray(result), _toConsumableArray(arg)) : [].concat(_toConsumableArray(result), [arg]); | ||
}; | ||
var toFlatArrayDeep = exports.toFlatArrayDeep = function toFlatArrayDeep(result, arg) { | ||
return Array.isArray(arg) ? [].concat(_toConsumableArray(result), _toConsumableArray(arg.reduce(toFlatArrayDeep, []))) : [].concat(_toConsumableArray(result), [arg]); | ||
}; | ||
var toFlatObject = exports.toFlatObject = function toFlatObject(result, obj) { | ||
return _extends({}, result, obj); | ||
}; | ||
var toFlatEntries = exports.toFlatEntries = function toFlatEntries(result, _ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
return _extends({}, result, _defineProperty({}, key, value)); | ||
}; | ||
var pickBy = exports.pickBy = function pickBy(obj, fn) { | ||
return Object.entries(obj).filter(function (_ref3) { | ||
var _ref4 = _slicedToArray(_ref3, 2), | ||
key = _ref4[0], | ||
value = _ref4[1]; | ||
return fn(value, key); | ||
}).reduce(toFlatEntries, {}); | ||
}; | ||
var parsePath = exports.parsePath = function parsePath() { | ||
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return isString(path) ? path.replace(/['"\]]/g, '').split(/[.[]/g).filter(function (item) { | ||
return item !== ''; | ||
}) : path; | ||
}; | ||
var get = exports.get = function get() { | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var path = arguments[1]; | ||
var keys = parsePath(path); | ||
return keys.reduce(function (result, key) { | ||
return result != null ? result[key] : result; | ||
}, target); | ||
}; | ||
var set = exports.set = function set() { | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var path = arguments[1]; | ||
var value = arguments[2]; | ||
var keys = parsePath(path); | ||
var _keys = _toArray(keys), | ||
key = _keys[0], | ||
nextKeys = _keys.slice(1); | ||
var nextValue = nextKeys.length > 0 ? set(target[key], nextKeys, value) : value; | ||
return _extends({}, target, _defineProperty({}, key, nextValue)); | ||
}; | ||
var groupByDeep = exports.groupByDeep = function groupByDeep(collection) { | ||
for (var _len = arguments.length, iteratees = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
iteratees[_key - 1] = arguments[_key]; | ||
} | ||
var paths = collection.map(function (value) { | ||
return iteratees.map(function (iteratee) { | ||
return iteratee(value); | ||
}); | ||
}); | ||
return paths.reduce(function (result, path, index) { | ||
var currentValue = get(result, path) || []; | ||
var newValue = currentValue.concat([collection[index]]); | ||
return _extends({}, result, set(result, path, newValue)); | ||
}, {}); | ||
}; |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
export const isString = arg => typeof arg === 'string' || arg instanceof String; | ||
@@ -11,2 +13,42 @@ | ||
export const isDateRange = (startDate, finalDate) => startDate !== finalDate; | ||
export const isDateRange = (startDate, finalDate) => startDate !== finalDate; | ||
export const toFlatArray = (result, arg) => Array.isArray(arg) ? [...result, ...arg] : [...result, arg]; | ||
export const toFlatArrayDeep = (result, arg) => Array.isArray(arg) ? [...result, ...arg.reduce(toFlatArrayDeep, [])] : [...result, arg]; | ||
export const toFlatObject = (result, obj) => _extends({}, result, obj); | ||
export const toFlatEntries = (result, [key, value]) => _extends({}, result, { [key]: value }); | ||
export const pickBy = (obj, fn) => Object.entries(obj).filter(([key, value]) => fn(value, key)).reduce(toFlatEntries, {}); | ||
export const parsePath = (path = []) => isString(path) ? path.replace(/['"\]]/g, '').split(/[.[]/g).filter(item => item !== '') : path; | ||
export const get = (target = {}, path) => { | ||
const keys = parsePath(path); | ||
return keys.reduce((result, key) => result != null ? result[key] : result, target); | ||
}; | ||
export const set = (target = {}, path, value) => { | ||
const keys = parsePath(path); | ||
const [key, ...nextKeys] = keys; | ||
const nextValue = nextKeys.length > 0 ? set(target[key], nextKeys, value) : value; | ||
return _extends({}, target, { | ||
[key]: nextValue | ||
}); | ||
}; | ||
export const groupByDeep = (collection, ...iteratees) => { | ||
const paths = collection.map(value => iteratees.map(iteratee => iteratee(value))); | ||
return paths.reduce((result, path, index) => { | ||
const currentValue = get(result, path) || []; | ||
const newValue = currentValue.concat([collection[index]]); | ||
return _extends({}, result, set(result, path, newValue)); | ||
}, {}); | ||
}; |
{ | ||
"name": "sling-web-helpers", | ||
"version": "0.6.0", | ||
"version": "0.8.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31812
683