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.
npm install cli-pages
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"
}
]);
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!"
});
...
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
Pages are created by using the 'Book'
class that is included in this package.
const { Book } = require("cli-pages"); // importing the class from the package
let pages = new Book(); // creating our pages
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!"
});
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!']
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
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
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
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
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)
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
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.
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?
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.
Found a bug? Having an issue with the package? Open a new issue here!