UNPKG

scramble-generator

Version:
90 lines (62 loc) 2.98 kB
# scramble-generator [![npm](https://img.shields.io/npm/v/scramble-generator.svg)](https://www.npmjs.com/package/scramble-generator) npm install scramble-generator **0.2.0 has breaking changes**. If you're using &lt; v0.2.0, see the [upgrading section](#upgrading). ## API <!-- Generated by documentation.js. Update this documentation by updating the source code. --> ### generateScramble Generates a random scramble for the given cube size. **Parameters** - `$0` **any** (optional, default `{}`) - `$0.cubeSize` (optional, default `3`) - `$0.length` (optional, default `(cubeSize-2)*20||8`) - `$0.formatted` (optional, default `true`) **Examples** ```javascript import generateScramble from 'scramble-generator'; generateScramble(); // R' U F D' L ... generateScramble({ cubeSize: 3, formatted: false }); // [ { face: 'U', inverted: false, double: true }, // { face: 'R', inverted: true, double: false }, // { face: 'D', inverted: false, double: true }, ... ] ``` Returns **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;Move>)** ### formatScramble Formats a given scramble as a string. **Parameters** - `scramble` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;Move>** List of Move objects representing a scramble to be formatted. **Examples** ```javascript import { formatScramble } from 'scramble-generator'; import { Faces } from 'scramble-utils-common'; format([{ face: Faces.R, inverted: true }, { face: Faces.U, double: true }, { face: Faces.L }]) // "R' U2 L" ``` Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** String representation of the given scramble. ## Upgrading ### From v0.1.x **v0.2.0 has breaking changes**. To upgrade from an earlier version: ```javascript // Before: import { formatted, generate, format, parse } from 'scramble-generator'; formatted(); // R U' D ... const scramble = generate(); // [{ face: 'R', longFace: 'RIGHT', inverted: true, double: false }, ...] format(scramble) // R' ... parse("R' U L") // [{ face: 'R', longFace: 'RIGHT', inverted: true, double: false }, ...] // After import generateScramble, { formatScramble } from 'scramble-generator'; import parseScramble from 'scramble-parser'; generateScramble(); // R U' D ... const scramble = generateScramble({ formatted: false }); // [{ face: 'R', inverted: true, double: false }, ...] (NB: `longFace` has been removed) formatScramble(scramble); // R' ... parseScramble("R' U L"); // [{ face: 'R', inverted: true, double: false }, ...] (NB: `longFace` has been removed) ``` These breaking changes are necessary to facilitate moving towards v1.0.0, after which the package will adhere strictly to semver. There might be some more breaking changes