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

@pluginjs/utils

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pluginjs/utils - npm Package Compare versions

Comparing version 0.7.9 to 0.7.10

574

dist/utils.common.js
/*!
* @pluginjs/utils v0.7.9 (https://pluginjs.com)
* @pluginjs/utils v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var is = require('@pluginjs/is');
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 _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(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"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
const nub = arr => {
return Array.from(new Set(arr));
};
const each = (obj, callback) => {
if (is.isArray(obj)) {
let index = 0;
const length = obj.length;
for (; index < length; index++) {
callback(obj[index], index);
}
} else {
Object.entries(obj).map((_ref) => {
let _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return callback(key, value);
});
}
return obj;
};
/** to createEvent */
function triggerNative(el, event, data) {
const e = document.createEvent('HTMLEvents');
if (typeof data !== 'undefined') {
e.initCustomEvent(event, true, true, data);
} else {
e.initEvent(event, true, false);
}
el.dispatchEvent(e);
}
/** Credit to https://github.com/jonschlinkert/shallow-clone MIT */
const clone = val => {
if (is.isElement(val)) {
return val;
} else if (is.isArray(val)) {
return val.slice();
} else if (is.isDate(val)) {
return new val.constructor(Number(val));
} else if (is.isMap(val)) {
return new Map(val);
} else if (is.isSet(val)) {
return new Set(val);
} else if (is.isSymbol(val)) {
return Symbol.prototype.valueOf ? Object(Symbol.prototype.valueOf.call(val)) : {};
} else if (is.isRegexp(val)) {
const re = new val.constructor(val.source, /\w+$/.exec(val));
re.lastIndex = val.lastIndex;
return re;
} else if (is.isError(val)) {
return Object.create(val);
} else if (is.isPlainObject(val)) {
return Object.assign({}, val);
}
return val;
};
/** Credit to https://github.com/jonschlinkert/clone-deep MIT */
const deepClone = val => {
if (is.isPlainObject(val)) {
return deepCloneObject(val);
} else if (is.isArray(val)) {
return deepCloneArray(val);
}
return clone(val);
};
const deepCloneObject = obj => {
if (is.isPlainObject(obj)) {
const res = new obj.constructor();
for (const key in obj) {
// eslint-disable-line
res[key] = deepClone(obj[key]);
}
return res;
}
return obj;
};
const deepCloneArray = arr => {
const res = new arr.constructor(arr.length);
for (let i = 0; i < arr.length; i++) {
res[i] = deepClone(arr[i]);
}
return res;
};
const merge = function merge(target) {
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
sources[_key - 1] = arguments[_key];
}
sources.forEach(src => {
for (const prop in src) {
// eslint-disable-line
target[prop] = src[prop];
}
});
return target;
};
function deepMergeTwo(target, source) {
const sourceIsArray = is.isArray(source);
const targetIsArray = is.isArray(target);
if (is.isUndefined(source)) {
return target;
}
if (sourceIsArray !== targetIsArray) {
return clone(source);
} else if (sourceIsArray) {
return clone(source);
} else if (is.isPlainObject(target) && is.isPlainObject(source)) {
Object.keys(source).forEach(key => {
target[key] = deepMergeTwo(target[key], source[key]);
});
return target;
}
return clone(source);
}
const deepMerge = function deepMerge() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return args.filter(is.isObject).reduce(deepMergeTwo, {});
};
const curry = function curry(fn) {
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return function () {
const currylen = fn.currylen || fn.length;
for (var _len3 = arguments.length, subArgs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
subArgs[_key3] = arguments[_key3];
}
const collect = args.concat(subArgs);
if (collect.length >= currylen) {
return fn(...collect);
}
return curry(fn, collect);
};
};
const curryWith = function curryWith(fn, enSureFunction) {
let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
return function () {
for (var _len4 = arguments.length, subArgs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
subArgs[_key4] = arguments[_key4];
}
const index = subArgs.findIndex(enSureFunction);
if (index >= 0) {
const collect = args.concat(...subArgs.slice(0, index + 1));
return fn(...collect);
}
const collect = args.concat(...subArgs);
return curryWith(fn, enSureFunction, collect);
};
};
const compose = function compose() {
for (var _len5 = arguments.length, fn = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
fn[_key5] = arguments[_key5];
}
const callback = function callback() {
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
return fn.reduceRight((r, i, index) => {
if (Array.isArray(r) && index === fn.length - 1) {
return i(...r);
}
return i(r);
}, args);
};
callback.currylen = fn[fn.curylen || fn.length - 1].length;
return callback;
};
const MAX_UID = 1000000;
const getUID = prefix => {
do {
// eslint-disable-next-line no-bitwise
prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
} while (document.getElementById(prefix));
return prefix;
};
const range = v => Array.from({
length: v
}, (v, i) => i);
const reflow = element => element.offsetHeight;
const arrayEqual = (a, b) => {
if (a === b) {
return true;
}
if (typeof a === 'undefined' || typeof b === 'undefined') {
return false;
}
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
const objectEqual = (a, b) => {
const aProps = Object.getOwnPropertyNames(a);
const bProps = Object.getOwnPropertyNames(b);
if (aProps.length !== bProps.length) {
return false;
}
for (let i = 0; i < aProps.length; i++) {
const prop = aProps[i];
if (is.isArray(a[prop]) && is.isArray(b[prop])) {
if (!arrayEqual(a[prop], b[prop])) {
return false;
}
} else if (is.isObject(a[prop]) && is.isObject(b[prop])) {
if (!objectEqual(a[prop], b[prop])) {
return false;
}
} else if (a[prop] !== b[prop]) {
return false;
}
}
return true;
};
const arrayDiff = (a, b) => {
return a.filter(n => b.indexOf(n) < 0);
};
const arrayIntersect = (a, b) => {
let t;
if (b.length > a.length) {
t = b;
b = a;
a = t;
}
return a.filter(n => b.indexOf(n) !== -1);
};
const convertPercentageToFloat = n => parseFloat(n.slice(0, -1) / 100, 10);
const convertFloatToPercentage = n => {
if (n < 0) {
n = 0;
} else if (n > 1) {
n = 1;
}
return "".concat(parseFloat(n).toFixed(4) * 100, "%");
};
const convertMatrixToArray = value => {
if (value && value.substr(0, 6) === 'matrix') {
return value.replace(/^.*\((.*)\)$/g, '$1').replace(/px/g, '').split(/, +/);
}
return false;
};
const getTime = () => {
if (typeof window.performance !== 'undefined' && window.performance.now) {
return window.performance.now();
}
return Date.now();
};
const camelize = function camelize(word) {
let first = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
word = word.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
if (first) {
word = word.substring(0, 1).toUpperCase() + word.substring(1);
}
return word;
};
const dasherize = word => word.replace(/([a-z\d])([A-Z])/g, '$1-$2').toLowerCase();
/* Credit to https://github.com/jonschlinkert/get-value MIT */
const getValueByPath = (obj, path) => {
if (Object(obj) !== obj || typeof path === 'undefined') {
return obj;
}
if (path in obj) {
return obj[path];
}
const segs = path.split('.');
const length = segs.length;
if (!length) {
return undefined;
}
let i = -1;
while (obj && ++i < length) {
let key = segs[i];
while (key[key.length - 1] === '\\') {
key = "".concat(key.slice(0, -1), ".").concat(segs[++i]);
}
obj = obj[key];
}
return obj;
};
/* Throttle execution of a function.
* Especially useful for rate limiting execution of
* handlers on events like resize and scroll. */
function throttle(func, delay) {
var _this = this;
let running = false;
function resetRunning() {
running = false;
}
if (typeof delay !== 'undefined' || delay !== null) {
return function () {
const that = _this;
if (running) {
return;
}
running = true;
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
func.apply(that, args);
window.setTimeout(resetRunning, delay);
};
}
return function () {
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
args[_key8] = arguments[_key8];
}
const that = _this;
if (running) {
return;
}
running = true;
window.requestAnimationFrame(() => {
func.apply(that, args);
resetRunning();
});
};
}
/* Debounce execution of a function.
* Debouncing, unlike throttling, guarantees that a function
* is only executed a single time at the very end. */
function debounce(func) {
var _this2 = this;
let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
let timer;
return function () {
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
args[_key9] = arguments[_key9];
}
const that = _this2;
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(() => {
func.apply(that, args);
}, delay);
};
}
function fromPairs(arr) {
return arr.reduce((r, _ref3) => {
let _ref4 = _slicedToArray(_ref3, 2),
k = _ref4[0],
v = _ref4[1];
return _objectSpread({}, r, {
[k]: v
});
}, {});
}
const SvgElement = (tag, attrs) => {
const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
if (!attrs) {
return el;
}
for (const key in attrs) {
if (!Object.hasOwnProperty.call(attrs, key)) {
continue;
}
el.setAttribute(key, attrs[key]);
}
return el;
};
function parseDataOptions(dataset) {
return Object.entries(dataset).reduce((result, _ref5) => {
let _ref6 = _slicedToArray(_ref5, 2),
k = _ref6[0],
v = _ref6[1];
try {
const content = JSON.parse("{\"data\": ".concat(v.replace(/'/g, '"'), "}")).data;
return _objectSpread({}, result, {
[k]: content
});
} catch (err) {
return _objectSpread({}, result, {
[k]: v
});
}
}, {});
}
exports.SvgElement = SvgElement;
exports.arrayDiff = arrayDiff;
exports.arrayEqual = arrayEqual;
exports.arrayIntersect = arrayIntersect;
exports.camelize = camelize;
exports.clone = clone;
exports.compose = compose;
exports.convertFloatToPercentage = convertFloatToPercentage;
exports.convertMatrixToArray = convertMatrixToArray;
exports.convertPercentageToFloat = convertPercentageToFloat;
exports.curry = curry;
exports.curryWith = curryWith;
exports.dasherize = dasherize;
exports.debounce = debounce;
exports.deepClone = deepClone;
exports.deepCloneArray = deepCloneArray;
exports.deepCloneObject = deepCloneObject;
exports.deepMerge = deepMerge;
exports.each = each;
exports.fromPairs = fromPairs;
exports.getTime = getTime;
exports.getUID = getUID;
exports.getValueByPath = getValueByPath;
exports.merge = merge;
exports.nub = nub;
exports.objectEqual = objectEqual;
exports.parseDataOptions = parseDataOptions;
exports.range = range;
exports.reflow = reflow;
exports.throttle = throttle;
exports.triggerNative = triggerNative;

4

dist/utils.common.min.js
/*!
* @pluginjs/utils v0.7.9 (https://pluginjs.com)
* @pluginjs/utils v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var is=require("@pluginjs/is");function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){_defineProperty(e,r,t[r])})}return e}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_nonIterableRest()}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,r){var t=[],n=!0,o=!1,i=void 0;try{for(var a,c=e[Symbol.iterator]();!(n=(a=c.next()).done)&&(t.push(a.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return t}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}const nub=e=>Array.from(new Set(e)),each=(e,r)=>{if(is.isArray(e)){let t=0;const n=e.length;for(;t<n;t++)r(e[t],t)}else Object.entries(e).map(e=>{let t=_slicedToArray(e,2),n=t[0],o=t[1];return r(n,o)});return e};function triggerNative(e,r,t){const n=document.createEvent("HTMLEvents");void 0!==t?n.initCustomEvent(r,!0,!0,t):n.initEvent(r,!0,!1),e.dispatchEvent(n)}const clone=e=>{if(is.isElement(e))return e;if(is.isArray(e))return e.slice();if(is.isDate(e))return new e.constructor(Number(e));if(is.isMap(e))return new Map(e);if(is.isSet(e))return new Set(e);if(is.isSymbol(e))return Symbol.prototype.valueOf?Object(Symbol.prototype.valueOf.call(e)):{};if(is.isRegexp(e)){const r=new e.constructor(e.source,/\w+$/.exec(e));return r.lastIndex=e.lastIndex,r}return is.isError(e)?Object.create(e):is.isPlainObject(e)?Object.assign({},e):e},deepClone=e=>is.isPlainObject(e)?deepCloneObject(e):is.isArray(e)?deepCloneArray(e):clone(e),deepCloneObject=e=>{if(is.isPlainObject(e)){const r=new e.constructor;for(const t in e)r[t]=deepClone(e[t]);return r}return e},deepCloneArray=e=>{const r=new e.constructor(e.length);for(let t=0;t<e.length;t++)r[t]=deepClone(e[t]);return r},merge=function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return t.forEach(r=>{for(const t in r)e[t]=r[t]}),e};function deepMergeTwo(e,r){const t=is.isArray(r),n=is.isArray(e);return is.isUndefined(r)?e:t!==n?clone(r):t?clone(r):is.isPlainObject(e)&&is.isPlainObject(r)?(Object.keys(r).forEach(t=>{e[t]=deepMergeTwo(e[t],r[t])}),e):clone(r)}const deepMerge=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];return r.filter(is.isObject).reduce(deepMergeTwo,{})},curry=function e(r){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return function(){const n=r.currylen||r.length;for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];const c=t.concat(i);return c.length>=n?r(...c):e(r,c)}},curryWith=function e(r,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return function(){for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];const c=i.findIndex(t);if(c>=0){const e=n.concat(...i.slice(0,c+1));return r(...e)}const s=n.concat(...i);return e(r,t,s)}},compose=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];const n=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.reduceRight((e,t,n)=>Array.isArray(e)&&n===r.length-1?t(...e):t(e),t)};return n.currylen=r[r.curylen||r.length-1].length,n},MAX_UID=1e6,getUID=e=>{do{e+=~~(1e6*Math.random())}while(document.getElementById(e));return e},range=e=>Array.from({length:e},(e,r)=>r),reflow=e=>e.offsetHeight,arrayEqual=(e,r)=>{if(e===r)return!0;if(void 0===e||void 0===r)return!1;if(e.length!==r.length)return!1;for(let t=0;t<e.length;++t)if(e[t]!==r[t])return!1;return!0},objectEqual=(e,r)=>{const t=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(r);if(t.length!==n.length)return!1;for(let n=0;n<t.length;n++){const o=t[n];if(is.isArray(e[o])&&is.isArray(r[o])){if(!arrayEqual(e[o],r[o]))return!1}else if(is.isObject(e[o])&&is.isObject(r[o])){if(!objectEqual(e[o],r[o]))return!1}else if(e[o]!==r[o])return!1}return!0},arrayDiff=(e,r)=>e.filter(e=>r.indexOf(e)<0),arrayIntersect=(e,r)=>{let t;return r.length>e.length&&(t=r,r=e,e=t),e.filter(e=>-1!==r.indexOf(e))},convertPercentageToFloat=e=>parseFloat(e.slice(0,-1)/100,10),convertFloatToPercentage=e=>(e<0?e=0:e>1&&(e=1),"".concat(100*parseFloat(e).toFixed(4),"%")),convertMatrixToArray=e=>!(!e||"matrix"!==e.substr(0,6))&&e.replace(/^.*\((.*)\)$/g,"$1").replace(/px/g,"").split(/, +/),getTime=()=>void 0!==window.performance&&window.performance.now?window.performance.now():Date.now(),camelize=function(e){let r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e=e.replace(/[_.\- ]+(\w|$)/g,(e,r)=>r.toUpperCase()),r&&(e=e.substring(0,1).toUpperCase()+e.substring(1)),e},dasherize=e=>e.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),getValueByPath=(e,r)=>{if(Object(e)!==e||void 0===r)return e;if(r in e)return e[r];const t=r.split("."),n=t.length;if(!n)return;let o=-1;for(;e&&++o<n;){let r=t[o];for(;"\\"===r[r.length-1];)r="".concat(r.slice(0,-1),".").concat(t[++o]);e=e[r]}return e};function throttle(e,r){var t=this;let n=!1;function o(){n=!1}return void 0!==r||null!==r?function(){const i=t;if(!n){n=!0;for(var a=arguments.length,c=new Array(a),s=0;s<a;s++)c[s]=arguments[s];e.apply(i,c),window.setTimeout(o,r)}}:function(){for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];const c=t;n||(n=!0,window.requestAnimationFrame(()=>{e.apply(c,i),o()}))}}function debounce(e){var r=this;let t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return function(){for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];const c=r;t&&(clearTimeout(t),t=null),t=setTimeout(()=>{e.apply(c,i)},n)}}function fromPairs(e){return e.reduce((e,r)=>{let t=_slicedToArray(r,2);return _objectSpread({},e,{[t[0]]:t[1]})},{})}const SvgElement=(e,r)=>{const t=document.createElementNS("http://www.w3.org/2000/svg",e);if(!r)return t;for(const e in r)Object.hasOwnProperty.call(r,e)&&t.setAttribute(e,r[e]);return t};function parseDataOptions(e){return Object.entries(e).reduce((e,r)=>{let t=_slicedToArray(r,2),n=t[0],o=t[1];try{return _objectSpread({},e,{[n]:JSON.parse('{"data": '.concat(o.replace(/'/g,'"'),"}")).data})}catch(r){return _objectSpread({},e,{[n]:o})}},{})}exports.SvgElement=SvgElement,exports.arrayDiff=arrayDiff,exports.arrayEqual=arrayEqual,exports.arrayIntersect=arrayIntersect,exports.camelize=camelize,exports.clone=clone,exports.compose=compose,exports.convertFloatToPercentage=convertFloatToPercentage,exports.convertMatrixToArray=convertMatrixToArray,exports.convertPercentageToFloat=convertPercentageToFloat,exports.curry=curry,exports.curryWith=curryWith,exports.dasherize=dasherize,exports.debounce=debounce,exports.deepClone=deepClone,exports.deepCloneArray=deepCloneArray,exports.deepCloneObject=deepCloneObject,exports.deepMerge=deepMerge,exports.each=each,exports.fromPairs=fromPairs,exports.getTime=getTime,exports.getUID=getUID,exports.getValueByPath=getValueByPath,exports.merge=merge,exports.nub=nub,exports.objectEqual=objectEqual,exports.parseDataOptions=parseDataOptions,exports.range=range,exports.reflow=reflow,exports.throttle=throttle,exports.triggerNative=triggerNative;
/*!
* @pluginjs/utils v0.7.9 (https://pluginjs.com)
* @pluginjs/utils v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
import { isArray, isElement, isDate, isMap, isSet, isSymbol, isRegexp, isError, isPlainObject, isObject, isUndefined } from '@pluginjs/is';
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 _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(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"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
const nub = arr => {
return Array.from(new Set(arr));
};
const each = (obj, callback) => {
if (isArray(obj)) {
let index = 0;
const length = obj.length;
for (; index < length; index++) {
callback(obj[index], index);
}
} else {
Object.entries(obj).map((_ref) => {
let _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return callback(key, value);
});
}
return obj;
};
/** to createEvent */
function triggerNative(el, event, data) {
const e = document.createEvent('HTMLEvents');
if (typeof data !== 'undefined') {
e.initCustomEvent(event, true, true, data);
} else {
e.initEvent(event, true, false);
}
el.dispatchEvent(e);
}
/** Credit to https://github.com/jonschlinkert/shallow-clone MIT */
const clone = val => {
if (isElement(val)) {
return val;
} else if (isArray(val)) {
return val.slice();
} else if (isDate(val)) {
return new val.constructor(Number(val));
} else if (isMap(val)) {
return new Map(val);
} else if (isSet(val)) {
return new Set(val);
} else if (isSymbol(val)) {
return Symbol.prototype.valueOf ? Object(Symbol.prototype.valueOf.call(val)) : {};
} else if (isRegexp(val)) {
const re = new val.constructor(val.source, /\w+$/.exec(val));
re.lastIndex = val.lastIndex;
return re;
} else if (isError(val)) {
return Object.create(val);
} else if (isPlainObject(val)) {
return Object.assign({}, val);
}
return val;
};
/** Credit to https://github.com/jonschlinkert/clone-deep MIT */
const deepClone = val => {
if (isPlainObject(val)) {
return deepCloneObject(val);
} else if (isArray(val)) {
return deepCloneArray(val);
}
return clone(val);
};
const deepCloneObject = obj => {
if (isPlainObject(obj)) {
const res = new obj.constructor();
for (const key in obj) {
// eslint-disable-line
res[key] = deepClone(obj[key]);
}
return res;
}
return obj;
};
const deepCloneArray = arr => {
const res = new arr.constructor(arr.length);
for (let i = 0; i < arr.length; i++) {
res[i] = deepClone(arr[i]);
}
return res;
};
const merge = function merge(target) {
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
sources[_key - 1] = arguments[_key];
}
sources.forEach(src => {
for (const prop in src) {
// eslint-disable-line
target[prop] = src[prop];
}
});
return target;
};
function deepMergeTwo(target, source) {
const sourceIsArray = isArray(source);
const targetIsArray = isArray(target);
if (isUndefined(source)) {
return target;
}
if (sourceIsArray !== targetIsArray) {
return clone(source);
} else if (sourceIsArray) {
return clone(source);
} else if (isPlainObject(target) && isPlainObject(source)) {
Object.keys(source).forEach(key => {
target[key] = deepMergeTwo(target[key], source[key]);
});
return target;
}
return clone(source);
}
const deepMerge = function deepMerge() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return args.filter(isObject).reduce(deepMergeTwo, {});
};
const curry = function curry(fn) {
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return function () {
const currylen = fn.currylen || fn.length;
for (var _len3 = arguments.length, subArgs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
subArgs[_key3] = arguments[_key3];
}
const collect = args.concat(subArgs);
if (collect.length >= currylen) {
return fn(...collect);
}
return curry(fn, collect);
};
};
const curryWith = function curryWith(fn, enSureFunction) {
let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
return function () {
for (var _len4 = arguments.length, subArgs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
subArgs[_key4] = arguments[_key4];
}
const index = subArgs.findIndex(enSureFunction);
if (index >= 0) {
const collect = args.concat(...subArgs.slice(0, index + 1));
return fn(...collect);
}
const collect = args.concat(...subArgs);
return curryWith(fn, enSureFunction, collect);
};
};
const compose = function compose() {
for (var _len5 = arguments.length, fn = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
fn[_key5] = arguments[_key5];
}
const callback = function callback() {
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
return fn.reduceRight((r, i, index) => {
if (Array.isArray(r) && index === fn.length - 1) {
return i(...r);
}
return i(r);
}, args);
};
callback.currylen = fn[fn.curylen || fn.length - 1].length;
return callback;
};
const MAX_UID = 1000000;
const getUID = prefix => {
do {
// eslint-disable-next-line no-bitwise
prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
} while (document.getElementById(prefix));
return prefix;
};
const range = v => Array.from({
length: v
}, (v, i) => i);
const reflow = element => element.offsetHeight;
const arrayEqual = (a, b) => {
if (a === b) {
return true;
}
if (typeof a === 'undefined' || typeof b === 'undefined') {
return false;
}
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
const objectEqual = (a, b) => {
const aProps = Object.getOwnPropertyNames(a);
const bProps = Object.getOwnPropertyNames(b);
if (aProps.length !== bProps.length) {
return false;
}
for (let i = 0; i < aProps.length; i++) {
const prop = aProps[i];
if (isArray(a[prop]) && isArray(b[prop])) {
if (!arrayEqual(a[prop], b[prop])) {
return false;
}
} else if (isObject(a[prop]) && isObject(b[prop])) {
if (!objectEqual(a[prop], b[prop])) {
return false;
}
} else if (a[prop] !== b[prop]) {
return false;
}
}
return true;
};
const arrayDiff = (a, b) => {
return a.filter(n => b.indexOf(n) < 0);
};
const arrayIntersect = (a, b) => {
let t;
if (b.length > a.length) {
t = b;
b = a;
a = t;
}
return a.filter(n => b.indexOf(n) !== -1);
};
const convertPercentageToFloat = n => parseFloat(n.slice(0, -1) / 100, 10);
const convertFloatToPercentage = n => {
if (n < 0) {
n = 0;
} else if (n > 1) {
n = 1;
}
return "".concat(parseFloat(n).toFixed(4) * 100, "%");
};
const convertMatrixToArray = value => {
if (value && value.substr(0, 6) === 'matrix') {
return value.replace(/^.*\((.*)\)$/g, '$1').replace(/px/g, '').split(/, +/);
}
return false;
};
const getTime = () => {
if (typeof window.performance !== 'undefined' && window.performance.now) {
return window.performance.now();
}
return Date.now();
};
const camelize = function camelize(word) {
let first = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
word = word.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
if (first) {
word = word.substring(0, 1).toUpperCase() + word.substring(1);
}
return word;
};
const dasherize = word => word.replace(/([a-z\d])([A-Z])/g, '$1-$2').toLowerCase();
/* Credit to https://github.com/jonschlinkert/get-value MIT */
const getValueByPath = (obj, path) => {
if (Object(obj) !== obj || typeof path === 'undefined') {
return obj;
}
if (path in obj) {
return obj[path];
}
const segs = path.split('.');
const length = segs.length;
if (!length) {
return undefined;
}
let i = -1;
while (obj && ++i < length) {
let key = segs[i];
while (key[key.length - 1] === '\\') {
key = "".concat(key.slice(0, -1), ".").concat(segs[++i]);
}
obj = obj[key];
}
return obj;
};
/* Throttle execution of a function.
* Especially useful for rate limiting execution of
* handlers on events like resize and scroll. */
function throttle(func, delay) {
var _this = this;
let running = false;
function resetRunning() {
running = false;
}
if (typeof delay !== 'undefined' || delay !== null) {
return function () {
const that = _this;
if (running) {
return;
}
running = true;
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
func.apply(that, args);
window.setTimeout(resetRunning, delay);
};
}
return function () {
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
args[_key8] = arguments[_key8];
}
const that = _this;
if (running) {
return;
}
running = true;
window.requestAnimationFrame(() => {
func.apply(that, args);
resetRunning();
});
};
}
/* Debounce execution of a function.
* Debouncing, unlike throttling, guarantees that a function
* is only executed a single time at the very end. */
function debounce(func) {
var _this2 = this;
let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
let timer;
return function () {
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
args[_key9] = arguments[_key9];
}
const that = _this2;
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(() => {
func.apply(that, args);
}, delay);
};
}
function fromPairs(arr) {
return arr.reduce((r, _ref3) => {
let _ref4 = _slicedToArray(_ref3, 2),
k = _ref4[0],
v = _ref4[1];
return _objectSpread({}, r, {
[k]: v
});
}, {});
}
const SvgElement = (tag, attrs) => {
const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
if (!attrs) {
return el;
}
for (const key in attrs) {
if (!Object.hasOwnProperty.call(attrs, key)) {
continue;
}
el.setAttribute(key, attrs[key]);
}
return el;
};
function parseDataOptions(dataset) {
return Object.entries(dataset).reduce((result, _ref5) => {
let _ref6 = _slicedToArray(_ref5, 2),
k = _ref6[0],
v = _ref6[1];
try {
const content = JSON.parse("{\"data\": ".concat(v.replace(/'/g, '"'), "}")).data;
return _objectSpread({}, result, {
[k]: content
});
} catch (err) {
return _objectSpread({}, result, {
[k]: v
});
}
}, {});
}
export { SvgElement, arrayDiff, arrayEqual, arrayIntersect, camelize, clone, compose, convertFloatToPercentage, convertMatrixToArray, convertPercentageToFloat, curry, curryWith, dasherize, debounce, deepClone, deepCloneArray, deepCloneObject, deepMerge, each, fromPairs, getTime, getUID, getValueByPath, merge, nub, objectEqual, parseDataOptions, range, reflow, throttle, triggerNative };
/*!
* @pluginjs/utils v0.7.9 (https://pluginjs.com)
* @pluginjs/utils v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
import{isArray as t,isElement as e,isDate as r,isMap as n,isSet as o,isSymbol as c,isRegexp as i,isError as u,isPlainObject as l,isObject as a,isUndefined as f}from"@pluginjs/is";function s(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function g(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){s(t,e,r[e])})}return t}function h(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,c=void 0;try{for(var i,u=t[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(t){o=!0,c=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw c}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}const p=t=>Array.from(new Set(t)),w=(e,r)=>{if(t(e)){let t=0;const n=e.length;for(;t<n;t++)r(e[t],t)}else Object.entries(e).map(t=>{let e=h(t,2),n=e[0],o=e[1];return r(n,o)});return e};function y(t,e,r){const n=document.createEvent("HTMLEvents");void 0!==r?n.initCustomEvent(e,!0,!0,r):n.initEvent(e,!0,!1),t.dispatchEvent(n)}const d=a=>{if(e(a))return a;if(t(a))return a.slice();if(r(a))return new a.constructor(Number(a));if(n(a))return new Map(a);if(o(a))return new Set(a);if(c(a))return Symbol.prototype.valueOf?Object(Symbol.prototype.valueOf.call(a)):{};if(i(a)){const t=new a.constructor(a.source,/\w+$/.exec(a));return t.lastIndex=a.lastIndex,t}return u(a)?Object.create(a):l(a)?Object.assign({},a):a},v=e=>l(e)?m(e):t(e)?b(e):d(e),m=t=>{if(l(t)){const e=new t.constructor;for(const r in t)e[r]=v(t[r]);return e}return t},b=t=>{const e=new t.constructor(t.length);for(let r=0;r<t.length;r++)e[r]=v(t[r]);return e},O=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return r.forEach(e=>{for(const r in e)t[r]=e[r]}),t};function A(e,r){const n=t(r),o=t(e);return f(r)?e:n!==o?d(r):n?d(r):l(e)&&l(r)?(Object.keys(r).forEach(t=>{e[t]=A(e[t],r[t])}),e):d(r)}const j=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e.filter(a).reduce(A,{})},x=function t(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return function(){const n=e.currylen||e.length;for(var o=arguments.length,c=new Array(o),i=0;i<o;i++)c[i]=arguments[i];const u=r.concat(c);return u.length>=n?e(...u):t(e,u)}},E=function t(e,r){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return function(){for(var o=arguments.length,c=new Array(o),i=0;i<o;i++)c[i]=arguments[i];const u=c.findIndex(r);if(u>=0){const t=n.concat(...c.slice(0,u+1));return e(...t)}const l=n.concat(...c);return t(e,r,l)}},S=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];const n=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return e.reduceRight((t,r,n)=>Array.isArray(t)&&n===e.length-1?r(...t):r(t),r)};return n.currylen=e[e.curylen||e.length-1].length,n},P=t=>{do{t+=~~(1e6*Math.random())}while(document.getElementById(t));return t},$=t=>Array.from({length:t},(t,e)=>e),I=t=>t.offsetHeight,N=(t,e)=>{if(t===e)return!0;if(void 0===t||void 0===e)return!1;if(t.length!==e.length)return!1;for(let r=0;r<t.length;++r)if(t[r]!==e[r])return!1;return!0},T=(e,r)=>{const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(r);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o++){const c=n[o];if(t(e[c])&&t(r[c])){if(!N(e[c],r[c]))return!1}else if(a(e[c])&&a(r[c])){if(!T(e[c],r[c]))return!1}else if(e[c]!==r[c])return!1}return!0},C=(t,e)=>t.filter(t=>e.indexOf(t)<0),F=(t,e)=>{let r;return e.length>t.length&&(r=e,e=t,t=r),t.filter(t=>-1!==e.indexOf(t))},M=t=>parseFloat(t.slice(0,-1)/100,10),k=t=>(t<0?t=0:t>1&&(t=1),"".concat(100*parseFloat(t).toFixed(4),"%")),D=t=>!(!t||"matrix"!==t.substr(0,6))&&t.replace(/^.*\((.*)\)$/g,"$1").replace(/px/g,"").split(/, +/),H=()=>void 0!==window.performance&&window.performance.now?window.performance.now():Date.now(),L=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t=t.replace(/[_.\- ]+(\w|$)/g,(t,e)=>e.toUpperCase()),e&&(t=t.substring(0,1).toUpperCase()+t.substring(1)),t},U=t=>t.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),q=(t,e)=>{if(Object(t)!==t||void 0===e)return t;if(e in t)return t[e];const r=e.split("."),n=r.length;if(!n)return;let o=-1;for(;t&&++o<n;){let e=r[o];for(;"\\"===e[e.length-1];)e="".concat(e.slice(0,-1),".").concat(r[++o]);t=t[e]}return t};function z(t,e){var r=this;let n=!1;function o(){n=!1}return void 0!==e||null!==e?function(){const c=r;if(!n){n=!0;for(var i=arguments.length,u=new Array(i),l=0;l<i;l++)u[l]=arguments[l];t.apply(c,u),window.setTimeout(o,e)}}:function(){for(var e=arguments.length,c=new Array(e),i=0;i<e;i++)c[i]=arguments[i];const u=r;n||(n=!0,window.requestAnimationFrame(()=>{t.apply(u,c),o()}))}}function B(t){var e=this;let r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return function(){for(var o=arguments.length,c=new Array(o),i=0;i<o;i++)c[i]=arguments[i];const u=e;r&&(clearTimeout(r),r=null),r=setTimeout(()=>{t.apply(u,c)},n)}}function J(t){return t.reduce((t,e)=>{let r=h(e,2);return g({},t,{[r[0]]:r[1]})},{})}const R=(t,e)=>{const r=document.createElementNS("http://www.w3.org/2000/svg",t);if(!e)return r;for(const t in e)Object.hasOwnProperty.call(e,t)&&r.setAttribute(t,e[t]);return r};function Z(t){return Object.entries(t).reduce((t,e)=>{let r=h(e,2),n=r[0],o=r[1];try{return g({},t,{[n]:JSON.parse('{"data": '.concat(o.replace(/'/g,'"'),"}")).data})}catch(e){return g({},t,{[n]:o})}},{})}export{R as SvgElement,C as arrayDiff,N as arrayEqual,F as arrayIntersect,L as camelize,d as clone,S as compose,k as convertFloatToPercentage,D as convertMatrixToArray,M as convertPercentageToFloat,x as curry,E as curryWith,U as dasherize,B as debounce,v as deepClone,b as deepCloneArray,m as deepCloneObject,j as deepMerge,w as each,J as fromPairs,H as getTime,P as getUID,q as getValueByPath,O as merge,p as nub,T as objectEqual,Z as parseDataOptions,$ as range,I as reflow,z as throttle,y as triggerNative};
/*!
* @pluginjs/utils v0.7.9 (https://pluginjs.com)
* @pluginjs/utils v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pluginjs/is')) :
typeof define === 'function' && define.amd ? define(['exports', '@pluginjs/is'], factory) :
(global = global || self, factory(global['@pluginjs/utils'] = {}, global['@pluginjs/is']));
}(this, function (exports, is) { 'use strict';
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 _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
function _iterableToArrayLimit(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"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
var nub = function nub(arr) {
return Array.from(new Set(arr));
};
var each = function each(obj, callback) {
if (is.isArray(obj)) {
var index = 0;
var length = obj.length;
for (; index < length; index++) {
callback(obj[index], index);
}
} else {
Object.entries(obj).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return callback(key, value);
});
}
return obj;
};
/** to createEvent */
function triggerNative(el, event, data) {
var e = document.createEvent('HTMLEvents');
if (typeof data !== 'undefined') {
e.initCustomEvent(event, true, true, data);
} else {
e.initEvent(event, true, false);
}
el.dispatchEvent(e);
}
/** Credit to https://github.com/jonschlinkert/shallow-clone MIT */
var clone = function clone(val) {
if (is.isElement(val)) {
return val;
} else if (is.isArray(val)) {
return val.slice();
} else if (is.isDate(val)) {
return new val.constructor(Number(val));
} else if (is.isMap(val)) {
return new Map(val);
} else if (is.isSet(val)) {
return new Set(val);
} else if (is.isSymbol(val)) {
return Symbol.prototype.valueOf ? Object(Symbol.prototype.valueOf.call(val)) : {};
} else if (is.isRegexp(val)) {
var re = new val.constructor(val.source, /\w+$/.exec(val));
re.lastIndex = val.lastIndex;
return re;
} else if (is.isError(val)) {
return Object.create(val);
} else if (is.isPlainObject(val)) {
return Object.assign({}, val);
}
return val;
};
/** Credit to https://github.com/jonschlinkert/clone-deep MIT */
var deepClone = function deepClone(val) {
if (is.isPlainObject(val)) {
return deepCloneObject(val);
} else if (is.isArray(val)) {
return deepCloneArray(val);
}
return clone(val);
};
var deepCloneObject = function deepCloneObject(obj) {
if (is.isPlainObject(obj)) {
var res = new obj.constructor();
for (var key in obj) {
// eslint-disable-line
res[key] = deepClone(obj[key]);
}
return res;
}
return obj;
};
var deepCloneArray = function deepCloneArray(arr) {
var res = new arr.constructor(arr.length);
for (var i = 0; i < arr.length; i++) {
res[i] = deepClone(arr[i]);
}
return res;
};
var merge = function merge(target) {
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
sources[_key - 1] = arguments[_key];
}
sources.forEach(function (src) {
for (var prop in src) {
// eslint-disable-line
target[prop] = src[prop];
}
});
return target;
};
function deepMergeTwo(target, source) {
var sourceIsArray = is.isArray(source);
var targetIsArray = is.isArray(target);
if (is.isUndefined(source)) {
return target;
}
if (sourceIsArray !== targetIsArray) {
return clone(source);
} else if (sourceIsArray) {
return clone(source);
} else if (is.isPlainObject(target) && is.isPlainObject(source)) {
Object.keys(source).forEach(function (key) {
target[key] = deepMergeTwo(target[key], source[key]);
});
return target;
}
return clone(source);
}
var deepMerge = function deepMerge() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return args.filter(is.isObject).reduce(deepMergeTwo, {});
};
var curry = function curry(fn) {
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return function () {
var currylen = fn.currylen || fn.length;
for (var _len3 = arguments.length, subArgs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
subArgs[_key3] = arguments[_key3];
}
var collect = args.concat(subArgs);
if (collect.length >= currylen) {
return fn.apply(void 0, _toConsumableArray(collect));
}
return curry(fn, collect);
};
};
var curryWith = function curryWith(fn, enSureFunction) {
var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
return function () {
for (var _len4 = arguments.length, subArgs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
subArgs[_key4] = arguments[_key4];
}
var index = subArgs.findIndex(enSureFunction);
if (index >= 0) {
var _collect = args.concat.apply(args, _toConsumableArray(subArgs.slice(0, index + 1)));
return fn.apply(void 0, _toConsumableArray(_collect));
}
var collect = args.concat.apply(args, subArgs);
return curryWith(fn, enSureFunction, collect);
};
};
var compose = function compose() {
for (var _len5 = arguments.length, fn = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
fn[_key5] = arguments[_key5];
}
var callback = function callback() {
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
return fn.reduceRight(function (r, i, index) {
if (Array.isArray(r) && index === fn.length - 1) {
return i.apply(void 0, _toConsumableArray(r));
}
return i(r);
}, args);
};
callback.currylen = fn[fn.curylen || fn.length - 1].length;
return callback;
};
var MAX_UID = 1000000;
var getUID = function getUID(prefix) {
do {
// eslint-disable-next-line no-bitwise
prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
} while (document.getElementById(prefix));
return prefix;
};
var range = function range(v) {
return Array.from({
length: v
}, function (v, i) {
return i;
});
};
var reflow = function reflow(element) {
return element.offsetHeight;
};
var arrayEqual = function arrayEqual(a, b) {
if (a === b) {
return true;
}
if (typeof a === 'undefined' || typeof b === 'undefined') {
return false;
}
if (a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
var objectEqual = function objectEqual(a, b) {
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
if (aProps.length !== bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var prop = aProps[i];
if (is.isArray(a[prop]) && is.isArray(b[prop])) {
if (!arrayEqual(a[prop], b[prop])) {
return false;
}
} else if (is.isObject(a[prop]) && is.isObject(b[prop])) {
if (!objectEqual(a[prop], b[prop])) {
return false;
}
} else if (a[prop] !== b[prop]) {
return false;
}
}
return true;
};
var arrayDiff = function arrayDiff(a, b) {
return a.filter(function (n) {
return b.indexOf(n) < 0;
});
};
var arrayIntersect = function arrayIntersect(a, b) {
var t;
if (b.length > a.length) {
t = b;
b = a;
a = t;
}
return a.filter(function (n) {
return b.indexOf(n) !== -1;
});
};
var convertPercentageToFloat = function convertPercentageToFloat(n) {
return parseFloat(n.slice(0, -1) / 100, 10);
};
var convertFloatToPercentage = function convertFloatToPercentage(n) {
if (n < 0) {
n = 0;
} else if (n > 1) {
n = 1;
}
return "".concat(parseFloat(n).toFixed(4) * 100, "%");
};
var convertMatrixToArray = function convertMatrixToArray(value) {
if (value && value.substr(0, 6) === 'matrix') {
return value.replace(/^.*\((.*)\)$/g, '$1').replace(/px/g, '').split(/, +/);
}
return false;
};
var getTime = function getTime() {
if (typeof window.performance !== 'undefined' && window.performance.now) {
return window.performance.now();
}
return Date.now();
};
var camelize = function camelize(word) {
var first = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
word = word.replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
return p1.toUpperCase();
});
if (first) {
word = word.substring(0, 1).toUpperCase() + word.substring(1);
}
return word;
};
var dasherize = function dasherize(word) {
return word.replace(/([a-z\d])([A-Z])/g, '$1-$2').toLowerCase();
};
/* Credit to https://github.com/jonschlinkert/get-value MIT */
var getValueByPath = function getValueByPath(obj, path) {
if (Object(obj) !== obj || typeof path === 'undefined') {
return obj;
}
if (path in obj) {
return obj[path];
}
var segs = path.split('.');
var length = segs.length;
if (!length) {
return undefined;
}
var i = -1;
while (obj && ++i < length) {
var key = segs[i];
while (key[key.length - 1] === '\\') {
key = "".concat(key.slice(0, -1), ".").concat(segs[++i]);
}
obj = obj[key];
}
return obj;
};
/* Throttle execution of a function.
* Especially useful for rate limiting execution of
* handlers on events like resize and scroll. */
function throttle(func, delay) {
var _this = this;
var running = false;
function resetRunning() {
running = false;
}
if (typeof delay !== 'undefined' || delay !== null) {
return function () {
var that = _this;
if (running) {
return;
}
running = true;
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
func.apply(that, args);
window.setTimeout(resetRunning, delay);
};
}
return function () {
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
args[_key8] = arguments[_key8];
}
var that = _this;
if (running) {
return;
}
running = true;
window.requestAnimationFrame(function () {
func.apply(that, args);
resetRunning();
});
};
}
/* Debounce execution of a function.
* Debouncing, unlike throttling, guarantees that a function
* is only executed a single time at the very end. */
function debounce(func) {
var _this2 = this;
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
var timer;
return function () {
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
args[_key9] = arguments[_key9];
}
var that = _this2;
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(function () {
func.apply(that, args);
}, delay);
};
}
function fromPairs(arr) {
return arr.reduce(function (r, _ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
k = _ref4[0],
v = _ref4[1];
return _objectSpread({}, r, _defineProperty({}, k, v));
}, {});
}
var SvgElement = function SvgElement(tag, attrs) {
var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
if (!attrs) {
return el;
}
for (var key in attrs) {
if (!Object.hasOwnProperty.call(attrs, key)) {
continue;
}
el.setAttribute(key, attrs[key]);
}
return el;
};
function parseDataOptions(dataset) {
return Object.entries(dataset).reduce(function (result, _ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
k = _ref6[0],
v = _ref6[1];
try {
var content = JSON.parse("{\"data\": ".concat(v.replace(/'/g, '"'), "}")).data;
return _objectSpread({}, result, _defineProperty({}, k, content));
} catch (err) {
return _objectSpread({}, result, _defineProperty({}, k, v));
}
}, {});
}
exports.SvgElement = SvgElement;
exports.arrayDiff = arrayDiff;
exports.arrayEqual = arrayEqual;
exports.arrayIntersect = arrayIntersect;
exports.camelize = camelize;
exports.clone = clone;
exports.compose = compose;
exports.convertFloatToPercentage = convertFloatToPercentage;
exports.convertMatrixToArray = convertMatrixToArray;
exports.convertPercentageToFloat = convertPercentageToFloat;
exports.curry = curry;
exports.curryWith = curryWith;
exports.dasherize = dasherize;
exports.debounce = debounce;
exports.deepClone = deepClone;
exports.deepCloneArray = deepCloneArray;
exports.deepCloneObject = deepCloneObject;
exports.deepMerge = deepMerge;
exports.each = each;
exports.fromPairs = fromPairs;
exports.getTime = getTime;
exports.getUID = getUID;
exports.getValueByPath = getValueByPath;
exports.merge = merge;
exports.nub = nub;
exports.objectEqual = objectEqual;
exports.parseDataOptions = parseDataOptions;
exports.range = range;
exports.reflow = reflow;
exports.throttle = throttle;
exports.triggerNative = triggerNative;
Object.defineProperty(exports, '__esModule', { value: true });
}));
/*!
* @pluginjs/utils v0.7.9 (https://pluginjs.com)
* @pluginjs/utils v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@pluginjs/is")):"function"==typeof define&&define.amd?define(["exports","@pluginjs/is"],e):e((r=r||self)["@pluginjs/utils"]={},r["@pluginjs/is"])}(this,function(r,e){"use strict";function n(r,e,n){return e in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function t(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},i=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(t).filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),i.forEach(function(e){n(r,e,t[e])})}return r}function i(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var n=[],t=!0,i=!1,o=void 0;try{for(var u,a=r[Symbol.iterator]();!(t=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);t=!0);}catch(r){i=!0,o=r}finally{try{t||null==a.return||a.return()}finally{if(i)throw o}}return n}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(r){return function(r){if(Array.isArray(r)){for(var e=0,n=new Array(r.length);e<r.length;e++)n[e]=r[e];return n}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var u=function(r){if(e.isElement(r))return r;if(e.isArray(r))return r.slice();if(e.isDate(r))return new r.constructor(Number(r));if(e.isMap(r))return new Map(r);if(e.isSet(r))return new Set(r);if(e.isSymbol(r))return Symbol.prototype.valueOf?Object(Symbol.prototype.valueOf.call(r)):{};if(e.isRegexp(r)){var n=new r.constructor(r.source,/\w+$/.exec(r));return n.lastIndex=r.lastIndex,n}return e.isError(r)?Object.create(r):e.isPlainObject(r)?Object.assign({},r):r},a=function(r){return e.isPlainObject(r)?c(r):e.isArray(r)?f(r):u(r)},c=function(r){if(e.isPlainObject(r)){var n=new r.constructor;for(var t in r)n[t]=a(r[t]);return n}return r},f=function(r){for(var e=new r.constructor(r.length),n=0;n<r.length;n++)e[n]=a(r[n]);return e};function l(r,n){var t=e.isArray(n),i=e.isArray(r);return e.isUndefined(n)?r:t!==i?u(n):t?u(n):e.isPlainObject(r)&&e.isPlainObject(n)?(Object.keys(n).forEach(function(e){r[e]=l(r[e],n[e])}),r):u(n)}var s=function(r,e){if(r===e)return!0;if(void 0===r||void 0===e)return!1;if(r.length!==e.length)return!1;for(var n=0;n<r.length;++n)if(r[n]!==e[n])return!1;return!0};r.SvgElement=function(r,e){var n=document.createElementNS("http://www.w3.org/2000/svg",r);if(!e)return n;for(var t in e)Object.hasOwnProperty.call(e,t)&&n.setAttribute(t,e[t]);return n},r.arrayDiff=function(r,e){return r.filter(function(r){return e.indexOf(r)<0})},r.arrayEqual=s,r.arrayIntersect=function(r,e){var n;return e.length>r.length&&(n=e,e=r,r=n),r.filter(function(r){return-1!==e.indexOf(r)})},r.camelize=function(r){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return r=r.replace(/[_.\- ]+(\w|$)/g,function(r,e){return e.toUpperCase()}),e&&(r=r.substring(0,1).toUpperCase()+r.substring(1)),r},r.clone=u,r.compose=function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];var t=function(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return e.reduceRight(function(r,n,t){return Array.isArray(r)&&t===e.length-1?n.apply(void 0,o(r)):n(r)},n)};return t.currylen=e[e.curylen||e.length-1].length,t},r.convertFloatToPercentage=function(r){return r<0?r=0:r>1&&(r=1),"".concat(100*parseFloat(r).toFixed(4),"%")},r.convertMatrixToArray=function(r){return!(!r||"matrix"!==r.substr(0,6))&&r.replace(/^.*\((.*)\)$/g,"$1").replace(/px/g,"").split(/, +/)},r.convertPercentageToFloat=function(r){return parseFloat(r.slice(0,-1)/100,10)},r.curry=function r(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return function(){for(var t=e.currylen||e.length,i=arguments.length,u=new Array(i),a=0;a<i;a++)u[a]=arguments[a];var c=n.concat(u);return c.length>=t?e.apply(void 0,o(c)):r(e,c)}},r.curryWith=function r(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return function(){for(var i=arguments.length,u=new Array(i),a=0;a<i;a++)u[a]=arguments[a];var c=u.findIndex(n);if(c>=0){var f=t.concat.apply(t,o(u.slice(0,c+1)));return e.apply(void 0,o(f))}var l=t.concat.apply(t,u);return r(e,n,l)}},r.dasherize=function(r){return r.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase()},r.debounce=function(r){var e,n=this,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return function(){for(var i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];var a=n;e&&(clearTimeout(e),e=null),e=setTimeout(function(){r.apply(a,o)},t)}},r.deepClone=a,r.deepCloneArray=f,r.deepCloneObject=c,r.deepMerge=function(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return n.filter(e.isObject).reduce(l,{})},r.each=function(r,n){if(e.isArray(r))for(var t=0,o=r.length;t<o;t++)n(r[t],t);else Object.entries(r).map(function(r){var e=i(r,2),t=e[0],o=e[1];return n(t,o)});return r},r.fromPairs=function(r){return r.reduce(function(r,e){var o=i(e,2);return t({},r,n({},o[0],o[1]))},{})},r.getTime=function(){return void 0!==window.performance&&window.performance.now?window.performance.now():Date.now()},r.getUID=function(r){do{r+=~~(1e6*Math.random())}while(document.getElementById(r));return r},r.getValueByPath=function(r,e){if(Object(r)!==r||void 0===e)return r;if(e in r)return r[e];var n=e.split("."),t=n.length;if(t){for(var i=-1;r&&++i<t;){for(var o=n[i];"\\"===o[o.length-1];)o="".concat(o.slice(0,-1),".").concat(n[++i]);r=r[o]}return r}},r.merge=function(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),t=1;t<e;t++)n[t-1]=arguments[t];return n.forEach(function(e){for(var n in e)r[n]=e[n]}),r},r.nub=function(r){return Array.from(new Set(r))},r.objectEqual=function r(n,t){var i=Object.getOwnPropertyNames(n),o=Object.getOwnPropertyNames(t);if(i.length!==o.length)return!1;for(var u=0;u<i.length;u++){var a=i[u];if(e.isArray(n[a])&&e.isArray(t[a])){if(!s(n[a],t[a]))return!1}else if(e.isObject(n[a])&&e.isObject(t[a])){if(!r(n[a],t[a]))return!1}else if(n[a]!==t[a])return!1}return!0},r.parseDataOptions=function(r){return Object.entries(r).reduce(function(r,e){var o=i(e,2),u=o[0],a=o[1];try{return t({},r,n({},u,JSON.parse('{"data": '.concat(a.replace(/'/g,'"'),"}")).data))}catch(e){return t({},r,n({},u,a))}},{})},r.range=function(r){return Array.from({length:r},function(r,e){return e})},r.reflow=function(r){return r.offsetHeight},r.throttle=function(r,e){var n=this,t=!1;function i(){t=!1}return void 0!==e||null!==e?function(){var o=n;if(!t){t=!0;for(var u=arguments.length,a=new Array(u),c=0;c<u;c++)a[c]=arguments[c];r.apply(o,a),window.setTimeout(i,e)}}:function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];var a=n;t||(t=!0,window.requestAnimationFrame(function(){r.apply(a,o),i()}))}},r.triggerNative=function(r,e,n){var t=document.createEvent("HTMLEvents");void 0!==n?t.initCustomEvent(e,!0,!0,n):t.initEvent(e,!0,!1),r.dispatchEvent(t)},Object.defineProperty(r,"__esModule",{value:!0})});

@@ -14,3 +14,3 @@ {

},
"version": "0.7.9",
"version": "0.7.10",
"category": "utils",

@@ -37,8 +37,8 @@ "main": "dist/utils.common.js",

"dependencies": {
"@pluginjs/is": "^0.7.8"
"@pluginjs/is": "^0.7.9"
},
"devDependencies": {
"@babel/core": "^7.4.4",
"@pluginjs/browserslist-config": "^1.2.5",
"@pluginjs/cli": "^0.7.8",
"@pluginjs/browserslist-config": "^1.2.6",
"@pluginjs/cli": "^0.7.9",
"babel-jest": "*",

@@ -68,3 +68,4 @@ "jest": "*",

"extends @pluginjs/browserslist-config"
]
],
"gitHead": "9ae759d6378f7bd8b952e5c1951dec91a101966e"
}
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