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

@cfi-notebook/content-map

v1.2.1

Published

A strategy for selecting documents from a library of documents and referencing sections or groups of sections.

Downloads

9

Readme

cfi-notebook/content-map

repo npm

A strategy for selecting documents from a library of documents and referencing sections or groups of sections.

Definitions

Document

A document is an object that has a title, slug, array of sections, and any other attributes you wish. It has a select function which can select a subset of sections.

Library

A library is an object which has an array of documents and a selector that can both select documents and sections within a selected document.

Section

A group of pages that can be referenced by their ref. For example, ref 3, or chapter 3, might be found on pages 54 through 69, and ref 5-3-1 might be found on pages 121 through 121.

Section Map

The section map is the data structure which maps a ref such as 1-1 to a page number.

Shorthand Reference

A shorthand reference is a way of using a string to select one or more sections. For example, 1-1,1-2 would section sections 1-1 and 1-2. See the usage examples for more detail.

Selection

A selection is the returned object from the select function on a document. It returns an object with two attributes, the sections array of the selected sections refs, and the pages array with the page numbers of the selection in sequential order.

Reference Types

String

A reference can be a String, for example, 'Preface' is a string reference. String references cannot be incremented.

Chapter

A reference can be a chapter, for example, 2 would reference chapter 2 that might be found on page 20. The return value is always a string.

Ref-Ref

References such as 1-1 or 6-2-5 are "ref-ref" references. The digits after the last hyphen are incremented. Endashes and emdashes are replaced with hyphens.

Sync

Sometimes a document has no section structure so we will revert to using page numbers as refs. A single shorthand reference of sync along with the first and last page is used to denote this situation. For example, sync#1#56 would be used to sync the section map to pages 1 through 56.

Usage

Include the library. Intended for use in Node, but it would work in the browser if consumed by something like Webpack to package and transpile via babel.

var ContentMap = require('@cfi-notebook/content-map');

Create Document from Object

var document = ContentMap.create({
  title: 'A Generic Handbook',
  sections: [
    {
      ref: '1-1',
      start: 1,
      end: 1
    },
    {
      ref: '1-2',
      start: 2,
      end: 2
    }
  ]
});

Create Document from Shorthand

var document = ContentMap.create({
  title: 'A Generic Handbook',
  sections: [
    '1-1#1',
    '1-2#2',
    '1-3#3#3' // last section must have a start and end
  ]
});

Create Document Using Sync

var document = ContentMap.create({
  title: 'A Generic Handbook',
  sections: ['sync#1#50']
});

Create Document from YAML

var filePath = path.resolve(__dirname, 'a-generic-handbook.yml');
var document = ContentMap.createFromYaml(filePath);

Create Library of Documents

var library = ContentMap.createAll([
  {
    title: 'A Generic Handbook',
    sections: ['sync#1#50']
  },
  {
    title: 'Some Other Handbook',
    sections: ['sync#1#50']
  }
]);

Create Library of Documents From YAML

var filePaths = ['a-generic-handbook.yml', 'some-other-handbook.yml'];
var library = ContentMap.createAllFromYaml(filePaths);

Select Sections of a Document

Single Section

document.select('1-1');

Multiple Sections

document.select('1-1,1-2'); // multiple sections separated by commas

Series of Sections

document.select('1-1...1-2'); // series of section from/to separated by ...

Select Document From Library

var library.select('a-generic-handbook');

Select Document From Library and Sections from Document

var library.select('[email protected]');