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

@status/label-maker

v1.1.0

Published

Generate endless labels

Downloads

71

Readme

Label Maker

Continuous label generator

Install

npm install @status/label-maker

or

yarn add @status/label-maker

Usage

Generate endless labels with @status/label-maker:

import { LabelMaker, labelMaker } from '@status/label-maker';

const labeler: LabelMaker = labelMaker('foo')('bar');

expect(labeler('baz').toString()).to.equal('foo|bar|baz');

Default delimiter is | but is easily changed:

const labeler: LabelMaker = labelMaker('foo', ':')('bar', '>')('baz', {
  includeFinalDelimiter: true,
  delimiter: '\t',
});

expect(`${labeler('qux', '|')}`).to.equal('foo:bar>baz   qux|');

Passing a label: (string) as first parameter is required. You may optionally provide an alternate delimiter: (string) as a second parameter, or an object with the properties described below.

Methods

after

Add a segment to the label after the specified position. Returns a new label maker.

const labeler: LabelMaker = labelMaker('foo')('bar').after(0, 'baz');

expect(labeler('qux').toString()).to.equal('foo|baz|bar|qux');

at

Add a segment to the label at the specified position. Returns a new label maker.

const labeler: LabelMaker = labelMaker('foo')('bar').at(1, 'baz');

expect(labeler('qux').toString()).to.equal('foo|baz|bar|qux');

before

Add a segment to the label before the specified position. Returns a new label maker.

const labeler: LabelMaker = labelMaker('foo')('bar').before(1, 'baz');

expect(labeler('qux').toString()).to.equal('baz|foo|bar|qux');

clear

Clear the label. Returns a new label maker.

const labeler: LabelMaker = labelMaker('foo')('bar').clear();

expect(labeler('qux').toString()).to.equal('');

get

Get the Label object at the specified position.

const labeler: LabelMaker = labelMaker('foo')('bar');

expect(labeler('baz').get(1)).to.deep.equal({
  label: 'bar',
  delimiter: '|',
  appendDelimiter: '',
  prependDelimiter: '',
  includeEmptySegments: false,
  includeFinalDelimiter: false,
  includePrependedDelimiter: false,
});

labels

Retrieves all the label objects.

const labeler: LabelMaker = labelMaker('foo')('bar');
const labels: Label[] = labeler('baz').labels();

expect(labels).to.have.lengthOf(3);

remove

Remove a segment from the label at the specified position. Returns a new label maker.

const labeler: LabelMaker = labelMaker('foo')('bar').remove(1);

expect(labeler('qux').toString()).to.equal('foo|qux');

replace

Replace a segment in the label at the specified position. Returns a new label maker.

const labeler: LabelMaker = labelMaker('foo')('bar').replace(1, 'baz');

expect(labeler('qux').toString()).to.equal('foo|baz|qux');

Options

appendDelimiter

Supply a final delimiter to use at the end of the label.

const labeler: LabelMaker = labelMaker('foo', ':')('bar', '>')('baz', {
  appendDelimiter: '|',
});

expect(labeler('qux').toString()).to.equal('foo:bar>baz>qux|');

delimiter

Delimiter to use between label segments. Default is |. Can vary between segments.

const labeler: LabelMaker = labelMaker('foo', ':')('bar', '>')('baz', {
  delimiter: '\t',
});

expect(labeler('qux').toString()).to.equal('foo:bar>baz   qux');

includeFinalDelimiter

Include final delimiter in the label. Default is false. Will use last provided value. Is set to true if appendDelimiter is provided.

const labeler: LabelMaker = labelMaker('foo', ':')('bar', '>')('baz', {
  includeFinalDelimiter: true,
});

expect(labeler('qux').toString()).to.equal('foo:bar>baz>qux>');

prependDelimiter

Delimiter to use before first segment.

const labeler: LabelMaker = labelMaker('foo', ':')('bar', '>')('baz', {
  prependDelimiter: '|',
});

expect(labeler('qux').toString()).to.equal('|foo:bar>baz>qux');

includePrependedDelimiter

Include delimiter before first segment. Default is false. Is set to true if prependDelimiter is provided.

const labeler: LabelMaker = labelMaker('foo', ':')('bar', '>')('baz', {
  includePrependedDelimiter: true,
});

expect(labeler('qux').toString()).to.equal('>foo:bar>baz>qux');