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

cli-pages

v1.2.6

Published

pagination for command line apps

Downloads

22

Readme

Contents

About

cli-pages is used to easily create pages for your command line interfaces and apps in no time! Want to create tutorials, policies, terms of service and more for your cli apps? cli-pages is perfect for you! It has all the features you possibly need! pages can be toggled by using custom words like 'n' or 'next' and 'p' or 'previous' or any other custom word. Custom words for exiting the book can also be set using .setCloseKey() function available in the 'Book' class.

Installation

npm install cli-pages

Example Usage

Creation

const { Book } = require("cli-pages");

let pages = new Book([
    {
        title: "Welcome to my app!",
        content: "This app does a lot of stuff! It can help you build a rocket!",
        footer: "Hope you enjoy!"
    },
    {
        title: "This is Amazing!",
        content: "epic!",
        footer: "Hope you understood!"
    },
    {
        title: "Thank you!",
        content: "Thank you for using my app! I really appreciate it!",
        footer: "<3"
    }
]);

OR

let pages = new Book();

pages.addPage({
    title: "Welcome to my app!",
    content: "This app does a lot of stuff! It can help you build a rocket!",
    footer: "Hope you enjoy!"
});
...

Displaying the pages in the terminal

const { Book } = require("cli-pages");

let pages = new Book([
    {
        title: "Welcome to my app!",
        content: "This app does a lot of stuff! It can help you build a rocket!",
        footer: "Hope you enjoy!"
    },
    {
        title: "This is Amazing!",
        content: "epic!",
        footer: "Hope you understood!"
    },
    {
        title: "Thank you!",
        content: "Thank you for using my app! I really appreciate it!",
        footer: "<3"
    }
]);

pages.open(); // displays the pages in the terminal

setTimeout(function(){
   pages.close(); // ends the page session and stops displaying the code after 60 seconds.
}, 60000)

Examples on how to edit, remove pages, get number of pages, set custom configurations can be found here

Documentation

Pages are created by using the 'Book' class that is included in this package.

Initializing

const { Book } = require("cli-pages"); // importing the class from the package

let pages = new Book(); // creating our pages

.addPage()

const { Book } = require("cli-pages"); 

let pages = new Book([
   {
      title: "hello!",
      content: "cli-pages is the best!",
      footer: "Thanks!"
   }
]);

There is an alternative to the above code! Use the .addPage() function

Parameters:

  • type: object
  • structure: { title: string, content: any, footer: string | undefined }
const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

.removePage()

Parameters:

  • type: number
  • structure: page-number: number
const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

pages.removePage(2); // removes the 2nd page [titled 'sup!']

.editPage()

Parameters:

  • type: number, object
  • structure: page-number, { title: string, content: any, footer: string | undefined }
const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

pages.editPage(1, { content: "this is the new content!" }); // edits content of the 1st page

.hasPage()

Parameters:

  • type: number
  • structure: page-number: number
const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

pages.hasPage(2); // returns true
pages.hasPage(6); // returns false

.size()

Parameters: none

const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

console.log(pages.size()); // prints 2

.open()

Parameters: none

const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

pages.open(); // displays the book in the console

.close()

Parameters: none

const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

pages.open(); // displays the book in the console

setTimeout(function(){
   pages.close(); // used to close the book. here it closes after 60 seconds of use
}, 60000)

.setCloseKey()

Parameters:

  • type: string
  • structure: key: string
const { Book } = require("cli-pages"); 

let pages = new Book();

pages.addPage({
  title: "hello!",
  content: "cli-pages is the best!",
  footer: "Thanks!"
});

pages.addPage({
  title: "sup!",
  content: "cli-pages is the worst!",
  footer: "Nope!"
});

pages.setCloseKey("exit"); // 'exit' here will be used to close the book on prompt

🤝 Contribution

For contributing to this project, fork the repository here, make the changes and open a pull request! Pull requests will be reviewed before being merged.

Format

Your pull request must contain the following information in detail -

  • Explain the pull request and the need for it to be merged in not more than 30 words
  • What did you add/edit?

Review

All pull requests are reviewed thoroughly. Pull requests that pass the review are merged and then closed while the pull requests that fail the review are not merged and are closed.

🐛 Bugs

Found a bug? Having an issue with the package? Open a new issue here!