npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nyinyithann/vec.js

v1.0.1

Published

Vec.js extends Javascript Array.

Downloads

4

Readme

Vec.js Node.js CI

Vec.js is a JavaScript library for nodeJS and browser. Vec.js extends JavaScript Array. The library is heavily inspired and influenced by F# Array module.

Documentation

Please go to Vec APIs to read more.

Installation

npm install @nyinyithann/vec.js

Getting started

Vec extends Array. All built-in methods of Array can be used with it. The following snippet demonstrates using Array's built-in method reduce with Vec.

const fnVec = Vec.of(
  (x) => x * x * x,
  (x) => x / 216,
  Math.sqrt
);
const howLongAStormLast = (d) => fnVec.reduce((s, f) => f(s), d);
console.log(howLongAStormLast(10.5)); // => 2.315032397181517

Vec has the following methods.

Static Methods

empty
init
create
isVec
some2
every2
fold2
foldRight2
forEach2
map2
map3
zip3
unfold
allPairs

Instance Methods

isEmpty
copy
countBy
findRight
findIndexRight
head
tail
get
set
last
take
takeWhile
skipWhile
min
max
minBy
maxBy
sum
sumBy
average
averageBy
splitAt
partition
scan
scanRight
windowed
zip
unzip
distinct
distinctBy
pairwise
except
groupBy
mapFold
mapFoldRight
chunkBySize
binarySearch
permute
transpose

Some sample code below.

// unfold
const fibonacci = (n) =>
  Vec.unfold(
    ([x, [a, b]]) => (x < n ? [a + b, [x + 1, [b, a + b]]] : null),
    [0, [0, 1]]
  );
const fibOf10 = fibonacci(10);
console.log(fibOf10);
// => [ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ]

// mapFold
const oneToTen = Vec.init(10, (x) => x + 1);
const mapFoldResult = oneToTen.mapFold((acc, elem) => [acc, acc + elem], 0);
console.log(mapFoldResult);
// => [ [ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45 ], 55 ]

// scan
const scannedResult = oneToTen.scan((acc, elem) => acc + elem, 0);
console.log(scannedResult);
// => [ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 ]

// groups
const groups = oneToTen.groupBy((x) => (x % 2 === 0 ? "Even" : "Odd"), true);
console.log(groups);
// => [ [ 'Odd', [ 1, 3, 5, 7, 9 ] ], [ 'Even', [ 2, 4, 6, 8, 10 ] ] ]

Vec can be instantiated as follows:

const vec = new Vec();
vec.push(1, 2, 3, 4, 5);
// => [ 1, 2, 3, 4, 5 ]

const vec1 = new Vec(1, 2, 3, 4, 5);
// => [ 1, 2, 3, 4, 5 ]

const vec2 = Vec.of(1, 2, 3, 4, 5);
// => [ 1, 2, 3, 4, 5 ]

const vec3 = Vec.from([1, 2, 3, 4, 5]);
// => [ 1, 2, 3, 4, 5 ]

const vec4 = Vec.init(5, (x) => x + 1);
// => [ 1, 2, 3, 4, 5 ]

const vec5 = Vec.unfold((x) => (x <= 5 ? [x, x + 1] : undefined), 1);
// => [ 1, 2, 3, 4, 5 ]

const vec6 = Vec.create(5, 1);
// => [ 1, 1, 1, 1, 1 ]

const emptyVec = Vec.empty();
emptyVec.push(1, 2, 3, 4, 5);
// => [ 1, 2, 3, 4, 5 ]

Please go to Vec APIs to read more.

Author

Nyi Nyi Than - @nyinyithann

Credit

License

MIT