UNPKG

scramble-generator

Version:
50 lines (45 loc) 1.35 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _scrambleUtilsCommon = require('scramble-utils-common'); /** * Formats a given scramble as a string. * @param [scramble] List of Move objects representing a scramble to be formatted. * @returns String representation of the given scramble. * @example * 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" */ var formatScramble = function formatScramble(scramble) { if (!Array.isArray(scramble)) return ''; return scramble.filter(function (move) { return _scrambleUtilsCommon.Faces[move.face]; }).map(function (_ref) { var double = _ref.double, inverted = _ref.inverted, layerCount = _ref.layerCount, face = _ref.face; var modifier = ''; if (layerCount > 1) { modifier += _scrambleUtilsCommon.Modifiers.WIDE; } if (double) { modifier += _scrambleUtilsCommon.Modifiers.DOUBLE; } else if (inverted) { modifier += _scrambleUtilsCommon.Modifiers.INVERTED; } return '' + (layerCount > 2 ? layerCount : '') + face + modifier; }).join(' '); }; exports.default = formatScramble;