GithubHelp home page GithubHelp logo

muskanmahajan37 / readme-box Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eddiejaoude/readme-box

0.0 0.0 0.0 431 KB

๐Ÿ“โš™๏ธ Lil' helper for replacing a section of the contents of a README.

License: MIT License

TypeScript 100.00%

readme-box's Introduction

README Box

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

NPM CI Codecov

Usage

Installation

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

You can quickly update a section of a README:

await ReadmeBox.updateSection('New contents!', {
  owner: 'JasonEtco',
  repo: 'example',
  token: process.env.GITHUB_TOKEN,
  section: 'example-section'
})

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.

readme-box's People

Contributors

jasonetco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.