Code Monkey home page Code Monkey logo

array-flatten's People

Contributors

aleclarson avatar blakeembrey avatar dependabot[bot] avatar greenkeeper[bot] avatar jamescostian avatar jimmywarting avatar nook-scheel avatar sreekanth370 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

array-flatten's Issues

benchmark fixtures used incorrectly

The benchmarked library checks (here) if the first arg is an array. When it is, it provides the args array as the arguments. Essentially unwrapping your fixture.

It appears you knew that and were dealing with it in here, and here.

It seems that no longer works tho. Those functions don't get called and the target functions are called with extra, unintended, arguments.

I noticed this when the "if-depth" benchmark was way faster than the others. I had it show its arguments the first time it ran and it was receiving a 'b' as the second arg. When I looked at "fixtures/large.js" I found that was the second element in the exported (outermost) array.

If I alter your fixtures files to wrap their exported value an extra time then they are used correctly for the flatten suite, but not the arguments/depth suites.

After looking at the source code for benchmarked I haven't seen a way to provide a similar option which will run those "extra wrapping" functions you have.

So, what I've done, for now, is put the current fixtures into a sub-directory named "fixtures/arguments", similar to "code/arguments". Then, created corresponding files in "fixtures/flatten" and "fixtures/depth" which require the ones in "fixtures/arguments" and wraps them. The "flatten" ones are only wrapped into an array. The "depth" ones are wrapped and a second element of 4 provided; same as what you had in the benchmark main file.

Include less files in package

Right now the package contains these files, which I think can be safely excluded:

  • .npmignore
  • .travis.yml
  • test.js

The test file and travis config could at least be added to the .npmignore or you can remove the .npmignore and use the files key in package.json for an even slimmer package :)

{
  "files": [
    "array-flatten.js",
    "LICENSE",
    "README.md"
  ]
}

(you don't have to add README.md explicitly)

Type instantiation is excessively deep and possibly infinite

Getting a ts error: Type instantiation is excessively deep and possibly infinite. ts(2589)

Minimal example:

import {flatten} from 'array-flatten';

const nestedArray = [
    ['c', 'd'],
    ['e', 'f'],
];
const concatArray = ['a', 'b'].concat(flatten(nestedArray)); // error is here
console.log(concatArray);
// [ 'a', 'b', 'c', 'd', 'e', 'f' ]

Workaround:

import {flatten} from 'array-flatten';

const nestedArray = [
    ['c', 'd'],
    ['e', 'f'],
];
// save off the flattened array first
const flattenedArray = flatten(nestedArray);
const concatArray = ['a', 'b'].concat(flattenedArray); // no error
console.log(concatArray);
// [ 'a', 'b', 'c', 'd', 'e', 'f' ]

Seems like a pretty weird edge case. I haven't looked into why it's happening. If it's not worth fixing, at least it's documented now ๐Ÿคทโ€โ™‚.

Typescript definition: NestedArray doesn't have array methods

Versions

  • array-flatten version: 2.1.0
  • typescript version: 2.1.5

Problem

When I try to compile the following example

import * as flatten from 'array-flatten';

const arr = flatten.depth<number>([[[1, 2]]], 1);
arr.push(1);

I get the error:

index.ts(4,5): error TS2339: Property 'push' does not exist on type 'NestedArray<number>'.

Expected behavior

No errors. NestedArray interface has methods from Array. Maybe define NestedArray like this:

interface NestedArray<T> extends Array<T | NestedArray<T>> {}

?

Passing a single string results in an array with an index for each character.

Since internally, this is assumed to be an array, (or at least array-like) it takes a string like abc and creates [ 'a', 'b', 'c' ]. This forces me to always wrap my arguments in an array literal:

flatten('abc');
// [ 'a', 'b', 'c' ]

flatten([ 'abc' ]);
// [ 'abc' ]

Would it be all right if strings were a special case that are assumed to be an array element? My hunch is that this is what most people would expect with strings, but I could be wrong.

JS Modules export?

Hi @blakeembrey!

This module is really popular! It's also nice and small, but I was wondering if you'd be open to providing a JS Modules version in addition to CommonJS? I'd be happy to PR. Let me know if you have a preference for tooling/etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.