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

@andatoshiki/readme-box

v1.0.1

Published

Lil' helper for replacing a section of the contents of a README.

Downloads

5

Readme

README-Box

Lil' helper for replacing a section of the contents of a README.

Usage

Installation

$ npm install @andatoshiki/readme-box
const { ReadmeBox } = require('@andatoshiki/readme-box')
import { ReadmeBox } from '@andatoshiki/readme-box'

You can quickly update a section of a README:

const result = await ReadmeBox.updateSection('New contents!', {
  owner: 'andatoshiki',
  repo: 'example',
  token: process.env.GITHUB_TOKEN,
  // branch is assumed to be 'master' by default, you can also specify `branch: 'master'`
  branch: 'master',
  section: 'example-section',
  // set to `true` to allow empty commits when there are no changes
  emptyCommits: false
})

// `result` is the response object of the README update request or
// `undefined` if no changes were made.

Or, if you need to access parts of it more granularly, you can use the ReadmeBox class methods:

const box = new ReadmeBox({ owner, repo, token })

// Get the contents of the README from the API
const { content, sha } = await box.getReadme()

// Get the contents of a section of the provided string
const sectionContents = box.getSection('example-section', content)

// Return a string with the replaced contents
const replacedContents = box.replaceSection({
  section: 'example-section',
  oldContent,
  newContent
})

// Update the README via the API, with an optional commit message
await box.updateReadme({ content, sha, message: 'Updating the README!' })

How it works

ReadmeBox.updateSection combines a couple of the methods exposed on the ReadmeBox class, to do the following:

  • Get the README file's contents from the API
  • Replace a section of it using Regular Expressions
  • Update the file via the API

It expects your README to have a "section", using HTML comments:

Check out this README!

<!--START_SECTION:example-section-->
Old contents...
<!--END_SECTION:example-section-->

When the above example code is run, everything between the start and end comments will be replaced.

Local Development

This project was bootstrapped with TSDX. Below is a list of commands you will probably find useful.

npm start

Runs the project in development/watch mode. The project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab. The library will be rebuilt if you make edits.

npm run build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module). s

npm test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.