Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@bob6664569/content-spinner

bob666456921MIT0.1.1

String content spinner with custom input to make it predictable

readme

content-spinner

code style: prettier

Node.js recursive content spinner algorithm with repetable behavior.

Based on string-content-spinner (@heek)

API

spin function

Spin a string.

Parameters:

spin(stringToSpin: string[, seed: string]);

Example without seed parameter:

const spin = require(-content-spinner');

const result = spin('{Hello|Good morning} world');

console.log(result);

This will log either Hello world or Good morning.

Example with a seed parameter:

const spin = require('predictable-content-spinner');

const result = spin('{Hello|Good morning} world', 'Random text');

console.log(result);

This example will always product the same output with the same string passed

factory function

Generates a new spin function with custom section markers and delimiter.

Parameters:

factory(openSectionMarker: string, closeSectionMarker: string, delimiter: string);

Example:

// Get factory function
const spinFactory = require('string-content-spinner').factory;

// Generate new spin function with custom section markers and delimiter
const spin = spinFactory('[[', ']]', '::');

// Use it!
const result = spin('Hello [[world::mars]]');

console.log(result);

This will log either Hello world or Hello mars.

Development

NPM commands

  • npm run prettier: run prettier on source files (both lib and test files)
  • npm run lint: lint source files (both lib and test files, using eslint)
  • npm test or npm run test: run unit tests
  • npm run git-add: run prettor, lint and unit tests, if all passed, stage changes