@vkontakte/vkjs
Advanced tools
Comparing version 0.26.0 to 0.27.0
@@ -15,2 +15,3 @@ "use strict"; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _uniqueArray = require("./internal/uniqueArray"); | ||
/** | ||
@@ -42,5 +43,9 @@ * Вычисляет сумму элементов массива | ||
function uniqueArray(array) { | ||
return array.filter(function (value, index, self) { | ||
return self.indexOf(value) === index; | ||
}); | ||
if (!Array.isArray(array) || !array.length) { | ||
return []; | ||
} | ||
if (typeof Set !== 'undefined') { | ||
return Array.from(new Set(array)); | ||
} | ||
return (0, _uniqueArray.uniqueArrayFallback)(array); | ||
} | ||
@@ -65,5 +70,8 @@ | ||
function chunkArray(array, size) { | ||
if (!array.length) { | ||
if (!Array.isArray(array) || !array.length) { | ||
return []; | ||
} | ||
if (!size) { | ||
return [array]; | ||
} | ||
var head = array.slice(0, size); | ||
@@ -70,0 +78,0 @@ var tail = array.slice(size); |
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import { uniqueArrayFallback } from './internal/uniqueArray'; | ||
/** | ||
@@ -28,5 +30,9 @@ * Вычисляет сумму элементов массива | ||
export function uniqueArray(array) { | ||
return array.filter(function (value, index, self) { | ||
return self.indexOf(value) === index; | ||
}); | ||
if (!Array.isArray(array) || !array.length) { | ||
return []; | ||
} | ||
if (typeof Set !== 'undefined') { | ||
return Array.from(new Set(array)); | ||
} | ||
return uniqueArrayFallback(array); | ||
} | ||
@@ -51,5 +57,8 @@ | ||
export function chunkArray(array, size) { | ||
if (!array.length) { | ||
if (!Array.isArray(array) || !array.length) { | ||
return []; | ||
} | ||
if (!size) { | ||
return [array]; | ||
} | ||
var head = array.slice(0, size); | ||
@@ -56,0 +65,0 @@ var tail = array.slice(size); |
@@ -49,2 +49,15 @@ export var noop = function noop() {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
} | ||
export function once(fn) { | ||
var called = false; | ||
return function () { | ||
if (called) { | ||
return; | ||
} | ||
called = true; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
return fn.apply(this, args); | ||
}; | ||
} | ||
//# sourceMappingURL=functions.js.map |
@@ -22,7 +22,4 @@ export { animate, animationEvent, transitionEvent, waitAnimationEnd, cancelWaitAnimationEnd, waitTransitionEnd, cancelWaitTransitionEnd } from './animate'; | ||
export { isPassiveEventsSupported, isSmoothScrollSupported } from './detections'; | ||
/** | ||
* equal | ||
*/ | ||
export { isEqual } from './equal'; | ||
export { noop, throttle, debounce, once } from './functions'; | ||
export { sumArray, averageArray, uniqueArray, shuffleArray, chunkArray, omitFromArray, difference } from './arrays'; | ||
@@ -33,3 +30,2 @@ export { asyncImportLoader } from './async'; | ||
export { formatDuration } from './duration'; | ||
export { noop, throttle, debounce } from './functions'; | ||
@@ -61,2 +57,3 @@ /** | ||
export { escapeRegExp } from './regexp'; | ||
export { isRetina } from './retina'; | ||
export { localStorage, sessionStorage } from './storage'; | ||
@@ -63,0 +60,0 @@ export { hasMouse, hasHover, hasTouchEvents, hasTouch } from './InputUtils'; |
@@ -10,1 +10,2 @@ export declare const noop: () => void; | ||
}; | ||
export declare function once<T extends (...args: any) => any>(fn: T): T; |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.noop = void 0; | ||
exports.once = once; | ||
exports.throttle = throttle; | ||
@@ -58,2 +59,15 @@ var noop = function noop() {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
} | ||
function once(fn) { | ||
var called = false; | ||
return function () { | ||
if (called) { | ||
return; | ||
} | ||
called = true; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
return fn.apply(this, args); | ||
}; | ||
} | ||
//# sourceMappingURL=functions.js.map |
@@ -7,2 +7,3 @@ export { animate, animationEvent, transitionEvent, waitAnimationEnd, cancelWaitAnimationEnd, waitTransitionEnd, cancelWaitTransitionEnd, } from './animate'; | ||
export { isEqual } from './equal'; | ||
export { noop, throttle, debounce, once } from './functions'; | ||
export { sumArray, averageArray, uniqueArray, shuffleArray, chunkArray, omitFromArray, difference, } from './arrays'; | ||
@@ -13,3 +14,2 @@ export { asyncImportLoader } from './async'; | ||
export { formatDuration } from './duration'; | ||
export { noop, throttle, debounce } from './functions'; | ||
export { getOffsetRect } from './getOffsetRect'; | ||
@@ -27,2 +27,3 @@ export { getPhotoSize } from './getPhotoSize'; | ||
export { escapeRegExp } from './regexp'; | ||
export { isRetina } from './retina'; | ||
export { localStorage, sessionStorage } from './storage'; | ||
@@ -29,0 +30,0 @@ export { hasMouse, hasHover, hasTouchEvents, hasTouch } from './InputUtils'; |
@@ -408,2 +408,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "isRetina", { | ||
enumerable: true, | ||
get: function get() { | ||
return _retina.isRetina; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameDate", { | ||
@@ -475,2 +481,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "once", { | ||
enumerable: true, | ||
get: function get() { | ||
return _functions.once; | ||
} | ||
}); | ||
Object.defineProperty(exports, "querystring", { | ||
@@ -542,2 +554,3 @@ enumerable: true, | ||
var _equal = require("./equal"); | ||
var _functions = require("./functions"); | ||
var _arrays = require("./arrays"); | ||
@@ -548,3 +561,2 @@ var _async = require("./async"); | ||
var _duration = require("./duration"); | ||
var _functions = require("./functions"); | ||
var _getOffsetRect = require("./getOffsetRect"); | ||
@@ -560,2 +572,3 @@ var _getPhotoSize = require("./getPhotoSize"); | ||
var _regexp = require("./regexp"); | ||
var _retina = require("./retina"); | ||
var _storage = require("./storage"); | ||
@@ -562,0 +575,0 @@ var _InputUtils = require("./InputUtils"); |
{ | ||
"name": "@vkontakte/vkjs", | ||
"version": "0.26.0", | ||
"version": "0.27.0", | ||
"description": "VK shared JS libs", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -0,1 +1,3 @@ | ||
import { uniqueArrayFallback } from './internal/uniqueArray'; | ||
/** | ||
@@ -25,5 +27,11 @@ * Вычисляет сумму элементов массива | ||
export function uniqueArray<T>(array: T[]): T[] { | ||
return array.filter((value, index, self) => { | ||
return self.indexOf(value) === index; | ||
}); | ||
if (!Array.isArray(array) || !array.length) { | ||
return []; | ||
} | ||
if (typeof Set !== 'undefined') { | ||
return Array.from(new Set(array)); | ||
} | ||
return uniqueArrayFallback(array); | ||
} | ||
@@ -45,5 +53,10 @@ | ||
export function chunkArray<T>(array: T[], size: number): T[][] { | ||
if (!array.length) { | ||
if (!Array.isArray(array) || !array.length) { | ||
return []; | ||
} | ||
if (!size) { | ||
return [array]; | ||
} | ||
const head = array.slice(0, size); | ||
@@ -50,0 +63,0 @@ const tail = array.slice(size); |
@@ -55,1 +55,13 @@ export const noop = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
} | ||
export function once<T extends (...args: any) => any>(fn: T) { | ||
let called = false; | ||
return function (...args) { | ||
if (called) { | ||
return; | ||
} | ||
called = true; | ||
return fn.apply(this, args); | ||
} as T; | ||
} |
@@ -31,7 +31,6 @@ export { | ||
/** | ||
* equal | ||
*/ | ||
export { isEqual } from './equal'; | ||
export { noop, throttle, debounce, once } from './functions'; | ||
export { | ||
@@ -69,4 +68,2 @@ sumArray, | ||
export { noop, throttle, debounce } from './functions'; | ||
/** | ||
@@ -116,2 +113,4 @@ * OffsetRect | ||
export { isRetina } from './retina'; | ||
export { localStorage, sessionStorage } from './storage'; | ||
@@ -118,0 +117,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
363035
198
5562