Socket
Socket
Sign inDemoInstall

prototypes

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prototypes - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

43

lib/array.js

@@ -117,5 +117,46 @@ 'use strict';

{
return [].concat.apply([], this);
var result = [];
for (var i = 0; i < this.length; i++)
{
var element = this[i];
if (Array.isArray(element))
{
for (var j = 0; j < element.length; j++)
{
result.push(element[j]);
}
}
else
{
result.push(element);
}
}
return result;
};
/**
* Returns the array flattened all the way.
*/
newArray.flatten = function()
{
var result = [];
for (var i = 0; i < this.length; i++)
{
var element = this[i];
if (Array.isArray(element))
{
var flattened = element.flatten();
for (var j = 0; j < flattened.length; j++)
{
result.push(flattened[j]);
}
}
else
{
result.push(element);
}
}
return result;
};
// add new object functions as properties

@@ -122,0 +163,0 @@ core.addProperties(Array.prototype, newArray);

2

package.json
{
"name": "prototypes",
"version": "1.0.0",
"version": "1.1.0",
"description": "Some common prototypes for node.js: string.startsWith(), object.countProperties() and more. Facilities for functional programming with objects: object.forEach(), object.filter(). Functions are added safely using Object.defineProperty().",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/prototypes",

@@ -349,2 +349,11 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/prototypes.png)](http://travis-ci.org/alexfernandez/prototypes)

### array.flatten()
Flattens all levels of nested arrays. Example:
```
[1, 2, [3, 4, [5, 6]]].concatAll();
\=> [1, 2, 3, 4, 5, 6]
```
### Array.toArray(object)

@@ -351,0 +360,0 @@

@@ -89,2 +89,16 @@ 'use strict';

function testConcatAll(callback)
{
var result = [1, 2, [3, 4, [5, 6]]].concatAll();
testing.assertEquals(result.length, 5, 'Should only flatten one level', callback);
testing.success(callback);
}
function testFlatten(callback)
{
var result = [1, 2, [3, 4, [5, 6]]].flatten();
testing.assertEquals(result.length, 6, 'Should flatten all the way', callback);
testing.success(callback);
}
function testToArray(callback)

@@ -104,9 +118,2 @@ {

function testConcatAll(callback)
{
var result = [1, 2, [3, 4, [5, 6]]].concatAll();
testing.assertEquals(result.length, 5, 'Should only flatten one level', callback);
testing.success(callback);
}
/**

@@ -124,4 +131,5 @@ * Run package tests.

testDifference,
testConcatAll,
testFlatten,
testToArray,
testConcatAll,
];

@@ -128,0 +136,0 @@ testing.run(tests, callback);

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