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

page-label-generator

v1.1.0

Published

Page Label Generator

Downloads

7

Readme

Page Label Generator

CircleCI

The Page Label Generator is a module that automatically generates page labels for "book-like" objects in a variety of ways. See the example usage section below to see the variety of page labeling options such as roman numberals, back-to-front, foliation, and starting numbers.

The Page Label Generator was originally written by Jon Stroop for Plum. This project cleans up some code, adds tape as a testing framework, and publishes it as a npm module for easy inclusion into browser-based apps.

Requires

If you want to run this code in the browser as part of your app, you will need webpack and you will need to add the babel polyfill at the top of your entry script like so:

import babelPolyfill from 'babel-polyfill'

Install

$ npm install

Test and Lint

$ npm test
$ npm run lint

Compile (Transpile to es5)

npm run compile

Example usage in web app

See the Webpack Demo project and the Tonic notebook.

Try it in the babel shell:

Start a shell session:

 $ babel-node

Basic Numbering


> let mod = require("./src/labelGen").default;
> let gen = mod.pageLabelGenerator();
> gen.next().value;
'1'
> gen.next().value;
'2'
> gen.next().value;
'3'

> let opts = { start: 1, unitLabel: "p. ", bracket: true}
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value;
'[p. 5]'
> gen.next().value;
'[p. 6]'
> gen.next().value;
'[p. 7]'
> gen.next().value;
'[p. 8]'


Foliation


> let mod = require("./src/labelGen").default;
> let opts = { start: 42, method: "foliate", frontLabel: " r", backLabel: " v", unitLabel: "f. "};
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value;
'f. 42 r'
> gen.next().value;
'f. 42 v'
> gen.next().value;
'f. 43 r'
> gen.next().value;
'f. 43 v'

> let opts = { start: 42, method: "foliate", frontLabel: "r", backLabel: "v", startWith: "back", unitLabel: "f. ", bracket: true};
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value;
'[f. 42v]'
> gen.next().value;
'[f. 43r]'
> gen.next().value;
'[f. 43v]'
> gen.next().value;
'[f. 44r]'
> gen.next().value;
'[f. 44v]'

Roman Numerals


> let mod = require("./src/labelGen").default;
> let opts = { start: 'i', unitLabel: "p. "};
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value;
'p. i'
> gen.next().value;
'p. ii'
> gen.next().value;
'p. iii'
> gen.next().value;
'p. iv'

> let opts = { start: 'xlii', method: "foliate", backLabel: " (verso)", startWith: "back", unitLabel: "f. ", bracket: true};
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value;
'[f. xlii (verso)]'
> gen.next().value;
'[f. xliii]'
> gen.next().value;
'[f. xliii (verso)]'
> gen.next().value;
'[f. xliv]'
> gen.next().value;
'[f. xliv (verso)]'
> gen.next().value;
'[f. xlv]'

> let opts = { unitLabel: 'p. ', bracketOdds: true };
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'[p. 1]'
> gen.next().value
'p. 2'
> gen.next().value
'[p. 3]'
> gen.next().value
'p. 4'

> let opts = { unitLabel: 'p. ', bracketEvens: true };
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'p. 1'
> gen.next().value
'[p. 2]'
> gen.next().value
'p. 3'
> gen.next().value
'[p. 4]'

2 Ups


> let mod = require("./src/labelGen").default;
> let opts = { start: 42, twoUp: true}
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'42/43'
> gen.next().value
'44/45'
> gen.next().value
'46/47'
> gen.next().value
'48/49'

> let opts = { start: 42, unitLabel: "p. ", twoUp: true, twoUpSeparator: "-"}
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'p. 43-42'
> gen.next().value
'p. 45-44'
> gen.next().value
'p. 47-46'
> gen.next().value
'p. 49-48'

> let opts = { start: 42, method: "foliate", frontLabel: "a", backLabel: "b", startWith: "back", unitLabel: "f. ", bracket: true, twoUp: true, twoUpDir: "rtl"}
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'[f. 43a/42b]'
> gen.next().value
'[f. 44a/43b]'
> gen.next().value
'[f. 45a/44b]'
> gen.next().value
'[f. 46a/45b]'

> let opts = { twoUp: true, twoUpBracketRightOnly: true };
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'1/[2]'
> gen.next().value
'3/[4]'
> gen.next().value
'5/[6]'
> gen.next().value
'7/[8]'

> let opts = { twoUp: true, twoUpBracketLeftOnly: true };
> let gen = mod.pageLabelGenerator(opts);
> gen.next().value
'[1]/2'
> gen.next().value
'[3]/4'
> gen.next().value
'[5]/6'
> gen.next().value
'[7]/8'

🤯