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

follows-order

v1.0.0

Published

Checks that specific array elements or string characters appear only in a certain order.

Downloads

3

Readme

follows-order

Checks that specific array elements or string characters appear only in a certain order. Packaged as a Node.js module.

Installation

npm install follows-order --save

The module exposes a single function.

Usage

Array Example

const followsOrder = require('follows-order')

const data = {
  name: "Test",
  description: "This is a test",
  module: "follows-order",
}

// Check to make sure that `name` precedes `description`.
// (Note: JavaScript does not guarantee object key order.
// This is only for the sake of example.)
followsOrder(Object.keys(data), ['name', 'description']) // true

String Example

const followsOrder = require('follows-order')

const data = 'test'

// Does the first "t" come before the first "e"?
followsOrder(data, 'te') // true

A Note on Duplicates

If an array or string is being checked to see if its order follows [A, B], then the first B cannot appear before the first A does, even if the [A, B] pattern occurs later.

This is according to design: the module is made to enforce a certain order, not merely check for a pattern.

| Data | Order | Result | Reason | | ------------ | --------- | ------ | ------ | | [B,A,B] | [A,B] | Fail | The first instance of A should have preceded the first instance of B. | | [A,B,B,A] | [A,B] | Pass | A and B only occur once in the order, so only the first instances in the data are checked. | | [A,B,B,A] | [A,B,A,B] | Fail | A and B occur twice in the order, so the second A in the data should have preceded the second B. |

const followsOrder = require('follows-order')

const data = [1, 2, 1]

followsOrder(data, [1, 2]) // true
followsOrder(data, [2, 1]) // false, because in the data the first instance of 1 occurs before 2
followsOrder(data, [1, 2, 1]) // true

If you don’t want to deal with duplicate elements in your data, you’ll need to deduplicate the data yourself before you check it with follows-order.