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 🙏

© 2026 – Pkg Stats / Ryan Hefner

slices.js

v1.0.3

Published

This NPM package aims to provide Golang-like array slices to Javascript. Array slices can be very useful when dealing with data partitioned within a flat array.

Readme

Slices.JS

This NPM package aims to provide Golang-like array slices to Javascript. Array slices can be very useful when dealing with data partitioned within a flat array.

Introduction

Example, self explanatory code.

const ArraySlice = require('slices.js');

const a = [1, 2, 3, 4, 5, 6, 7];
const b = new ArraySlice(a, 1, -3); // negative indices supported
// last index is -1, first index is -Array.length

// results [2, 3, 4, 5]
b[2] = 3;
// b = [2, 3, 3, 5]
b.reverse();
// b = [5, 3, 3, 2]
a
// [ 1, 5, 3, 3, 2, 6, 7 ]

Functions

Basic properties and methods

Properties and methods unique to the ArraySlice class.

Property: array, ArraySlice

Returns the parent array

const a = [1, 2, 3, 4, 5, 6, 7];
const b = new ArraySlice(a, 1, -3); // negative indices supported

a == b.array // true

Method: subarray , () -> Array

Returns the array slice as an array

b.subarray() // [2, 3, 4, 5] - an Array, NOT an ArraySlice
Array.isArray(b.subarray()) // true

Property: start, Int

Returns the starting index of the slice. Negative indices are converted to their equivalent positive one.

b.start // 1

Property: end, Int

Returns the ending index of the slice Negative indices are converted to their equivalent positive one.

b.end // 5

Method: mutmap, (appliedFunction : Function) -> ArraySlice

Apply and set the value of each value in the slice with a function

a // [1, 2, 3, 4, 5, 6, 7]
b // [2, 3, 4, 5]
b.mutmap(x => x + 1); // [3, 4, 5, 6]
a // [1, 3, 4, 5, 6, 6, 7]

Method: set, (newValues : Array) -> ArraySlice

Set the values of the ArraySlice to corresponding values in an Array

a // [1, 2, 3, 4, 5, 6, 7]
b // [2, 3, 4, 5]
b.set([1, 5, 3, 6]); // [1, 5, 3, 6]
a // [1, 1, 5, 3, 6, 6, 7]

Derived properties and methods

Properties of normal Javascript arrays that are applicable to Array Slices. All methods that act on the slice are destructive. The changes are also reflected in the parent array.

Property: length, Int

Gets the length of the ArraySlice

b // [2, 3, 4, 5]
b.length // 4

Method: copyWithin, (target : Int, start : Int, end : Int) -> ArraySlice

copyWithin is a clone of the corresponding Javascript function. One can think of this as C's memmove function with an array. It copies one portion of the array, specified by start and end, to another part who's starting index is specified by target.

a // [1, 2, 3, 4, 5, 6, 7]
b // [2, 3, 4, 5]
b.copyWithin(2, 0, 2) // [2, 3, 2, 3]
a // [1, 2, 3, 2, 3, 6, 7]

Method: fill, (value : Object) -> ArraySlice

Fills the entire slice with one value.

a // [1, 2, 3, 4, 5, 6, 7]
b // [2, 3, 4, 5]
b.fill(2) // [2, 2, 2, 2]
a // [1, 2, 2, 2, 2, 6, 7]

Method: reverse, () -> ArraySlice

Reverse the entire slice.

a // [1, 2, 3, 4, 5, 6, 7]
b // [2, 3, 4, 5]
b.reverse() // [5, 4, 3, 2]
a // [1, 5, 4, 3, 2, 6, 7]

Method: sort, (comparatorFunction : (a : Object, b : Object) -> Bool) -> ArraySlice

Sorts the slice according to the given comparator function

a // [1, 5, 2, 4, 3, 6, 7]
b // [5, 2, 4, 3]
b.sort((a, b) => a < b) // [2, 3, 4, 5]
a // [1, 2, 3, 4, 5, 6, 7]

Property: constructor, ArraySlice

Returns the ArraySlice constructor

new b.constructor([1, 2, 3]) // [1, 2, 3] is an ArraySlice

Method: valueOf, () -> Array

b // [5, 2, 4, 3]
b.valueOf() // [5, 2, 4, 3] is an Array
Array.isArray(b.valueOf()) // true

Other properties and methods

Nondestructive Array methods like the following:

concat, filter, includes, indexOf, join, lastIndexOf, slice, toString, toLocaleString, entries, every, find, findIndex, forEach, keys, map, reduce, reduceRight, some, values

are not supported; they do not well with the Array Slice model. One can easily use these functions with the subarray method instead. However, a native array will be returned instead of an array slice.

const a = [1, 2, 3, 4, 5, 6, 7];
const b = new ArraySlice(a, 1, -3); 

b.subarray().map(x => x + 1)
// [ 3, 4, 5, 6 ]