juliancoleman / orchestra

A dependency-free, pure-function String manipulation library
MIT License
1 stars 0 forks source link
javascript string-manipulation typescript

Orchestra

A dependency-free, Typescipt-first, pure-function String manipulation library

NPM

Build Status Build Status

Maintainability Test Coverage

codecov

Usage

Installation

# yarn
yarn add @juliancoleman/orchestra

# npm
npm i @juliancoleman/orchestra

Contribute

Fork & Clone

Feel free to fork and clone this repo to start out. Once cloned, go ahead and run one of the following commands:

# yarn
yarn

# npm
npm i

Testing

Note:

If you run into the following error while running the test suite on MacOS:

$ jest --config ./jest.config.js -i --watch

Error: `fsevents` unavailable (this watcher can only be used on Darwin)

then run the following:

brew install watchman

Test suite

You can run all tests in Orchestra by simply running:

# yarn
yarn test

# npm
npm run test

This command will spin up Jest, run all tests, and watch for additional changes to files. The watcher will restart if it detects a change in any .js or .ts file.

On the first run of Jest, it may report 0 suites found. Just hit a and let it find the suite.

Coverage reporting

Local (Terminal)

To view a map of the coverage report, run the following:

# yarn
yarn coverage

# npm
npm run coverage

This spins up jest, runs all tests, runs a coverage report, and prints the report to the console. This command does not watch for file changes.

Local (Browser)

# yarn
yarn coverage:serve

# npm
npm run coverage:serve

This spins up Jest, runs all tests, runs a coverage report, and spins up a web server, generating a URL when the server is ready. This command does not watch for file changes.

Writing your own tests

Jest has a very familiar feel to the likes of mocha and chai. To be as basic as possible, your test file will look something like this...

describe("#myFunction", () => {
  it("passes the test", () => {
    expect(true).toBe(true);
  });
});

Creating a new Orchestra method

So, you have a great idea on a new function you would like Orchestra to adopt. I appreciate the contribution!

  1. Hop into lib/ and create a new folder

The folder structure should look like the following

myFunction/
  - myFunction.ts
  - myFunction.spec.ts

(don't create any index.ts files)

  1. Begin creating your function.
    • Don't forget to utilize TypeScript and its type system.
    • Any contribution with missing types will be automatically rejected.
  2. Test your function.
    • use the example above to get started.
    • write as many tests you feel are necessary (the more, the better!).
    • Leaving the demo describe block in your test file will also earn you a rejection.
  3. Upon completion of the function and its tests, run the following command:
# yarn
yarn generate-barrels

# npm
npm run generate-barrels

This will automatically add an index.ts file to your new folder, as well as add your new function to the list of Orchestra's module exports. You won't need to worry about populating the index as barrelsby has already taken care of that for you. If you're unfamiliar with the barrel pattern, I can't recommend reading up on it enough.

You can then do something like this in a project that uses Orchestra as a dependency:

import { myFunction } from "orchestra";