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

arsub

v0.3.3

Published

An Array subclass providing a few missing methods

Downloads

7

Readme

arsub 0.3.3

A subclass of Array adding a few useful methods.

USAGE:
let A  = require ("arsub");
let ok = A.ok;
// ok (a,b) means a and b must be equal,
// else an error is thrown. ok() works
// also with Arrays and Objects, recursively

let a = A(1, 2, 3, 4, 5);
ok (a.size(), 5 );

// more examples below
RELEASE-ANNOUNCEMENTS:

https://twitter.com/ClassCloudLLC

0. MOTIVATING EXAMPLES

let a = A(1, 2, 3, 4, 5);

ok (a.first ()  ,  5 );
ok (a.first (1) , [5]);
ok (a.first (2) , [4, 5]);
ok (a.first (-1), [2,3,4,5]);
ok (a.first (-2), [3,4,5]);

ok (a.last ()  , 5 );
ok (a.last (1) , [5]);
ok (a.last (2) , [4. 5]);
ok (a.last (-1), [2,3,4,5]);
ok (a.last (-2), [3,4,5]);

// plus more, read the static method test():

1. INSTALLATION

npm install arsub

2. REQUIRING

A) With Node.js
const A  = require ("arsub");
// You can use it like Array so call it 'A'.
B) With browser
<script type="module">

 import A from './arsub_es6.js';
 let a = A (1,2,3);
 A.ok (a, [1,2,3]);

</script>

Open the file ./test_browser.html in your browser to test-run the above.

Use the above as example for how to import the ES6-module arsub_es6.js to your own browser-side html- or js-files.

Seems to work on latest versions of Edge, FireFox and Chrome.

3. API

3.1 Array-subclass Arsub
   const A  = require ("arsub");
   let ok   = A.ok;
   let a    = A (1,2,3); // Immutable

   ok (a. size    ); // The length
   ok (a. first   ); // First elements
   ok (a. last    ); // Last elements
   ok (a. addFirst); // Add new elements to the beginning
   ok (a. addLast ); // Add new elements to the end
   ok (a. copy    ); // (shallow) copy with overriding or new elements

   ok (a. get     ); // Get element from sparse array
   ok (a. put     ); // Put element to sparse array
   ok (a. eq      ); // Test array equality recursively

   ok (a. monad   ); // The monad bind-function.
   ok (a. m       ); // Same as monad
   ok (a. _       ); // Monad-terminal

   ok (a. of      ); // Create new instance with given elements

   // Above just lists all API-methods showing
   // by calling ok() that the above methods
   // do exist. Arsub is a subclass of Array so
   // in imnherits all Array-methods as well.
   //
   // Read the source of the static method
   // test() to see how they can be used.
3.2 Extra ok()
let ok = A.ok;

// The utility function ok() is
// used in the tests, piggy-backing
// with arsub.js since it is so useful.
// See the source-code it is not long

ok ([1,2], [1,2])

4. Tests

Tests are coded in and executed by the static test() -method of the class 'Arsub' defined in arsub.js.

When the class is defined those tests are run. That happens only once, when you load the module, not at runtime. Unless you explicitly call Arsub.test() again.

See the source Luke.

5. What does 'arsub' mean?

It means Array-subclass.

6. License

SPDX-License-Identifier: Apache-2.0