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

analog-array

v1.0.0

Published

AnalogArray by PropJokey - read values between array indexes

Downloads

4

Readme

James0x57

AnalogArray by PropJockey

npm i analog-array

Importing

npm and StealJS:

// any method:
import AnalogArray from "analog-array";
// or
const AnalogArray = require("analog-array");
// or
define(["analog-array"], function(AnalogArray){});

npm and CJS:

const AnalogArray = require("analog-array");

AMD:

require.config({
  packages: [{
    name: 'analog-array',
    location: 'node_modules/analog-array/dist/amd',
    main: 'analog-array'
  }]
});
// ...
define(["analog-array"], function(AnalogArray){});

Global/Standalone:

<script src="dist/global/analog-array.js"></script>
<!-- or -->
<script src="dist/global/analog-array.min.js"></script>

<script>
  const analogArray = new AnalogArray([10, 8, 999, 20000])
</script>

Usage

  let analogArray = new AnalogArray([10, 8, 16])

  Array.isArray(analogArray) // true

  // overflow access returns highest or lowest available index respectively:
  analogArray[999] // 16
  analogArray[-0.5] // 10

  // index values accessed like a normal array:
  analogArray[1] // 8

splitIndex values "slide" between the value at index = Math.floor(splitIndex) and the next index

  let analogArray = new AnalogArray([10, 8, 16])
  analogArray[0.5] // 9 (half way between index 0 and index 1)
  analogArray[1.25] // 10 (1/4 past the value at index 1 towards the value at index 2)
  analogArray[1.50] // 12 (1/2 past the value at index 1 towards the value at index 2)
  analogArray[1.75] // 14 (3/4 past the value at index 1 towards the value at index 2)
  analogArray[2.00] // 16 (the value at index 2)

a custom slide function can be specified

  analogArray = new AnalogArray([10, 8, 16], mySlideFn) // at init
  analogArray.slide = mySlideFn // or later

Slide functions take 3 arguments, (from, to, amount) from is the value at the index Math.floor(splitIndex) to is the value at the index Math.floor(splitIndex) + 1 amount is the scalar = splitIndex - fromIndex, which will be a value in the range (0, 1) (amounts 0 and 1 will access the array directly without sliding, otherwise the range would have been [0, 1])

Examples:

  let floorIndexValuesOnly = (from, to, amount) => {
    console.log(from, to, amount)
    return from
  }
  analogArray = new AnalogArray([10, 8, 16])

  analogArray[1.50] // 12
  analogArray.slide = floorIndexValuesOnly
  analogArray[1.50] // returns: 8, logs: 8 16 0.5

The values in the analogArray can be anything if you provide a way to slide between them.

Slide functions AnalogArray.slideNumber (the default slide) and AnalogArray.slideColor are included

These slide functions can be used directly outside of the implicit use in an AnalogArray instance if needed.

AnalogArray.slideColor

Accepts hex colors in the form "#RRGGBB". If "RRGGBB" is used (without "#") at Math.floor(splitIndex), the result will also omit "#".

let colorsAnalogArray = new AnalogArray(["#ff00ff", "888888", "#00ff00"], AnalogArray.slideColor)

colorsAnalogArray[0] // "#ff00ff"
colorsAnalogArray[0.5] // "#c444c4"
colorsAnalogArray[1] // "888888"
colorsAnalogArray[1.5] // "44c444"
colorsAnalogArray[2] // "#00ff00"

It will also slide hex colors in the form "#RRGGBBAA" and "RRGGBBAA" with similar results.