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

array-slice-x

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-slice-x - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

64

index.js
/**
* @file Cross-browser array slicer.
* @version 2.1.0
* @version 2.2.0
* @author Xotic750 <Xotic750@gmail.com>

@@ -21,2 +21,6 @@ * @copyright Xotic750

var hasArgumentsLengthBug = (function () {
return arguments.length !== 1;
}(1));
var setRelative = function _setRelative(value, length) {

@@ -26,6 +30,4 @@ return value < 0 ? Math.max(length + value, 0) : Math.min(value, length);

var internalSlice = function slice(array, start, end) {
var object = toObject(array);
var iterable = splitString && isString(object) ? object.split('') : object;
var length = toLength(iterable.length);
var internalSlice = function slice(object, start, end) {
var length = toLength(object.length);
var k = setRelative(toInteger(start), length);

@@ -38,4 +40,4 @@ var relativeEnd = isUndefined(end) ? length : toInteger(end);

while (k < finalEnd) {
if (k in iterable) {
val[next] = iterable[k];
if (k in object) {
val[next] = object[k];
}

@@ -50,39 +52,2 @@

var $slice;
try {
$slice = function slice(array, start, end) {
var object = toObject(array);
if (isArguments(object)) {
return internalSlice(object, start, end);
}
var iterable = splitString && isString(object) ? object.split('') : object;
return nativeSlice.apply(iterable, internalSlice(arguments, 1));
};
var str = $slice('ab');
if (str.length !== 2 || str[0] !== 'a' || str[1] !== 'b') {
throw new Error('failed string');
}
var obj = $slice({ 1: 1, length: 2 });
if (obj.length !== 2 || isUndefined(obj[0]) === false || 0 in obj || obj[1] !== 1) {
throw new Error('failed object');
}
var args = (function () {
return arguments;
}(void 0, 2));
if (args.length !== 2 || isUndefined(args[0]) === false || args[1] !== 2) {
throw new Error('failed arguments');
}
} catch (ignore) {
// eslint-disable-next-line no-console
console.error(ignore);
$slice = internalSlice;
}
/**

@@ -118,2 +83,11 @@ * The slice() method returns a shallow copy of a portion of an array into a new

*/
module.exports = $slice;
module.exports = function slice(array, start, end) {
var object = toObject(array);
if (hasArgumentsLengthBug === false && isArguments(object)) {
return internalSlice(object, start, end);
}
var iterable = splitString && isString(object) ? object.split('') : object;
return nativeSlice.apply(iterable, internalSlice(arguments, 1));
};
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.returnExports = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
/**
* @file Cross-browser array slicer.
* @version 2.1.0
* @version 2.2.0
* @author Xotic750 <Xotic750@gmail.com>

@@ -22,2 +22,6 @@ * @copyright Xotic750

var hasArgumentsLengthBug = (function () {
return arguments.length !== 1;
}(1));
var setRelative = function _setRelative(value, length) {

@@ -27,6 +31,4 @@ return value < 0 ? Math.max(length + value, 0) : Math.min(value, length);

var internalSlice = function slice(array, start, end) {
var object = toObject(array);
var iterable = splitString && isString(object) ? object.split('') : object;
var length = toLength(iterable.length);
var internalSlice = function slice(object, start, end) {
var length = toLength(object.length);
var k = setRelative(toInteger(start), length);

@@ -39,4 +41,4 @@ var relativeEnd = isUndefined(end) ? length : toInteger(end);

while (k < finalEnd) {
if (k in iterable) {
val[next] = iterable[k];
if (k in object) {
val[next] = object[k];
}

@@ -51,39 +53,2 @@

var $slice;
try {
$slice = function slice(array, start, end) {
var object = toObject(array);
if (isArguments(object)) {
return internalSlice(object, start, end);
}
var iterable = splitString && isString(object) ? object.split('') : object;
return nativeSlice.apply(iterable, internalSlice(arguments, 1));
};
var str = $slice('ab');
if (str.length !== 2 || str[0] !== 'a' || str[1] !== 'b') {
throw new Error('failed string');
}
var obj = $slice({ 1: 1, length: 2 });
if (obj.length !== 2 || isUndefined(obj[0]) === false || 0 in obj || obj[1] !== 1) {
throw new Error('failed object');
}
var args = (function () {
return arguments;
}(void 0, 2));
if (args.length !== 2 || isUndefined(args[0]) === false || args[1] !== 2) {
throw new Error('failed arguments');
}
} catch (ignore) {
// eslint-disable-next-line no-console
console.error(ignore);
$slice = internalSlice;
}
/**

@@ -119,4 +84,13 @@ * The slice() method returns a shallow copy of a portion of an array into a new

*/
module.exports = $slice;
module.exports = function slice(array, start, end) {
var object = toObject(array);
if (hasArgumentsLengthBug === false && isArguments(object)) {
return internalSlice(object, start, end);
}
var iterable = splitString && isString(object) ? object.split('') : object;
return nativeSlice.apply(iterable, internalSlice(arguments, 1));
};
},{"has-boxed-string-x":4,"is-arguments":5,"is-string":12,"to-integer-x":19,"to-length-x":20,"to-object-x":21,"validate.io-undefined":22}],2:[function(_dereq_,module,exports){

@@ -123,0 +97,0 @@ 'use strict';

!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).returnExports=f()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n||e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(_dereq_,module,exports){/**
* @file Cross-browser array slicer.
* @version 2.1.0
* @version 2.2.0
* @author Xotic750 <Xotic750@gmail.com>

@@ -9,3 +9,3 @@ * @copyright Xotic750

*/
"use strict";var $slice,toObject=_dereq_("to-object-x"),toInteger=_dereq_("to-integer-x"),toLength=_dereq_("to-length-x"),isUndefined=_dereq_("validate.io-undefined"),isString=_dereq_("is-string"),splitString=!1===_dereq_("has-boxed-string-x"),isArguments=_dereq_("is-arguments"),nativeSlice=Array.prototype.slice,setRelative=function _setRelative(value,length){return value<0?Math.max(length+value,0):Math.min(value,length)},internalSlice=function slice(array,start,end){var object=toObject(array),iterable=splitString&&isString(object)?object.split(""):object,length=toLength(iterable.length),k=setRelative(toInteger(start),length),relativeEnd=isUndefined(end)?length:toInteger(end),finalEnd=setRelative(relativeEnd,length),val=[];val.length=Math.max(finalEnd-k,0);for(var next=0;k<finalEnd;)k in iterable&&(val[next]=iterable[k]),next+=1,k+=1;return val};try{var str=($slice=function slice(array,start,end){var object=toObject(array);if(isArguments(object))return internalSlice(object,start,end);var iterable=splitString&&isString(object)?object.split(""):object;return nativeSlice.apply(iterable,internalSlice(arguments,1))})("ab");if(2!==str.length||"a"!==str[0]||"b"!==str[1])throw new Error("failed string");var obj=$slice({1:1,length:2});if(2!==obj.length||!1===isUndefined(obj[0])||0 in obj||1!==obj[1])throw new Error("failed object");var args=function(){return arguments}(void 0,2);if(2!==args.length||!1===isUndefined(args[0])||2!==args[1])throw new Error("failed arguments")}catch(ignore){console.error(ignore),$slice=internalSlice}module.exports=$slice},{"has-boxed-string-x":4,"is-arguments":5,"is-string":12,"to-integer-x":19,"to-length-x":20,"to-object-x":21,"validate.io-undefined":22}],2:[function(_dereq_,module,exports){"use strict";var keys=_dereq_("object-keys"),foreach=_dereq_("foreach"),hasSymbols="function"==typeof Symbol&&"symbol"==typeof Symbol(),toStr=Object.prototype.toString,isFunction=function(fn){return"function"==typeof fn&&"[object Function]"===toStr.call(fn)},supportsDescriptors=Object.defineProperty&&function(){var obj={};try{Object.defineProperty(obj,"x",{enumerable:!1,value:obj});for(var _ in obj)return!1;return obj.x===obj}catch(e){return!1}}(),defineProperty=function(object,name,value,predicate){(!(name in object)||isFunction(predicate)&&predicate())&&(supportsDescriptors?Object.defineProperty(object,name,{configurable:!0,enumerable:!1,value:value,writable:!0}):object[name]=value)},defineProperties=function(object,map){var predicates=arguments.length>2?arguments[2]:{},props=keys(map);hasSymbols&&(props=props.concat(Object.getOwnPropertySymbols(map))),foreach(props,function(name){defineProperty(object,name,map[name],predicates[name])})};defineProperties.supportsDescriptors=!!supportsDescriptors,module.exports=defineProperties},{foreach:3,"object-keys":16}],3:[function(_dereq_,module,exports){var hasOwn=Object.prototype.hasOwnProperty,toString=Object.prototype.toString;module.exports=function forEach(obj,fn,ctx){if("[object Function]"!==toString.call(fn))throw new TypeError("iterator must be a function");var l=obj.length;if(l===+l)for(var i=0;i<l;i++)fn.call(ctx,obj[i],i,obj);else for(var k in obj)hasOwn.call(obj,k)&&fn.call(ctx,obj[k],k,obj)}},{}],4:[function(_dereq_,module,exports){/**
"use strict";var toObject=_dereq_("to-object-x"),toInteger=_dereq_("to-integer-x"),toLength=_dereq_("to-length-x"),isUndefined=_dereq_("validate.io-undefined"),isString=_dereq_("is-string"),splitString=!1===_dereq_("has-boxed-string-x"),isArguments=_dereq_("is-arguments"),nativeSlice=Array.prototype.slice,hasArgumentsLengthBug=function(){return 1!==arguments.length}(1),setRelative=function _setRelative(value,length){return value<0?Math.max(length+value,0):Math.min(value,length)},internalSlice=function slice(object,start,end){var length=toLength(object.length),k=setRelative(toInteger(start),length),relativeEnd=isUndefined(end)?length:toInteger(end),finalEnd=setRelative(relativeEnd,length),val=[];val.length=Math.max(finalEnd-k,0);for(var next=0;k<finalEnd;)k in object&&(val[next]=object[k]),next+=1,k+=1;return val};module.exports=function slice(array,start,end){var object=toObject(array);if(!1===hasArgumentsLengthBug&&isArguments(object))return internalSlice(object,start,end);var iterable=splitString&&isString(object)?object.split(""):object;return nativeSlice.apply(iterable,internalSlice(arguments,1))}},{"has-boxed-string-x":4,"is-arguments":5,"is-string":12,"to-integer-x":19,"to-length-x":20,"to-object-x":21,"validate.io-undefined":22}],2:[function(_dereq_,module,exports){"use strict";var keys=_dereq_("object-keys"),foreach=_dereq_("foreach"),hasSymbols="function"==typeof Symbol&&"symbol"==typeof Symbol(),toStr=Object.prototype.toString,isFunction=function(fn){return"function"==typeof fn&&"[object Function]"===toStr.call(fn)},supportsDescriptors=Object.defineProperty&&function(){var obj={};try{Object.defineProperty(obj,"x",{enumerable:!1,value:obj});for(var _ in obj)return!1;return obj.x===obj}catch(e){return!1}}(),defineProperty=function(object,name,value,predicate){(!(name in object)||isFunction(predicate)&&predicate())&&(supportsDescriptors?Object.defineProperty(object,name,{configurable:!0,enumerable:!1,value:value,writable:!0}):object[name]=value)},defineProperties=function(object,map){var predicates=arguments.length>2?arguments[2]:{},props=keys(map);hasSymbols&&(props=props.concat(Object.getOwnPropertySymbols(map))),foreach(props,function(name){defineProperty(object,name,map[name],predicates[name])})};defineProperties.supportsDescriptors=!!supportsDescriptors,module.exports=defineProperties},{foreach:3,"object-keys":16}],3:[function(_dereq_,module,exports){var hasOwn=Object.prototype.hasOwnProperty,toString=Object.prototype.toString;module.exports=function forEach(obj,fn,ctx){if("[object Function]"!==toString.call(fn))throw new TypeError("iterator must be a function");var l=obj.length;if(l===+l)for(var i=0;i<l;i++)fn.call(ctx,obj[i],i,obj);else for(var k in obj)hasOwn.call(obj,k)&&fn.call(ctx,obj[k],k,obj)}},{}],4:[function(_dereq_,module,exports){/**
* @file Check support of by-index access of string characters.

@@ -12,0 +12,0 @@ * @version 1.0.0

{
"name": "array-slice-x",
"version": "2.1.0",
"version": "2.2.0",
"description": "Cross-browser array slicer.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/Xotic750/array-slice-x",

@@ -26,3 +26,3 @@ <a href="https://travis-ci.org/Xotic750/array-slice-x"

**Version**: 2.1.0
**Version**: 2.2.0
**Author**: Xotic750 <Xotic750@gmail.com>

@@ -33,3 +33,3 @@ **License**: [MIT](&lt;https://opensource.org/licenses/MIT&gt;)

### `module.exports` ⇒ <code>Array</code> ⏏
### `module.exports(array, [start], [end])` ⇒ <code>Array</code> ⏏
The slice() method returns a shallow copy of a portion of an array into a new

@@ -39,3 +39,3 @@ array object selected from begin to end (end not included). The original

**Kind**: Exported member
**Kind**: Exported function
**Returns**: <code>Array</code> - A new array containing the extracted elements.

@@ -42,0 +42,0 @@

Sorry, the diff of this file is not supported yet

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