Package Exports
- cube-notation-normalizer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cube-notation-normalizer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
cube-notation-normalizer
There are several number of rubik's cube related programs on npm, and many of them has their own function to parse algorithms. Typically, these functions only support limited syntax of algorithm notation.
This library intends to be a base for this kind of programs to support broad syntax of algorithm notation.
Install
$ npm install cube-notation-normalizer
Simple usage
const normalize = require('cube-notation-normalizer');
const ugly = "(rU R' U`) (r' FRF' ) ";
// default, human-readable format
normalize(ugly);
// => "r U R' U' r' F R F'"
// machine-friendly format
normalize(ugly, {
separator: '',
useModifiers: false,
uniformCenterMoves: 'slice'
});
// => "RMMMURRRUUURRRMFRFFF"
Supported syntax and features
Face turns, slice turns and cube rotations
normalize("R U F L D B M E S x y z");
// => "R U F L D B M E S r u f l d b x y z"
Double layer turns
normalize("r Uw");
// => "r u"
Whitespaces and comments
normalize(`
R U
R'U' // sexy move
/*
R' F R F' <- sledgehammer
*/
`);
// => "R U R' U'"
Invert
normalize("R' U` R´ Uʼ R’ U′ Ri");
// => "R' U' R' U' R' U' R'"
normalize("(R U F)'");
// => "F' U' R'"
Repetitions
normalize("R3 U18 (F D)2");
// => "R' U2 F D F D"
// '*' and '^' are optional
normalize("R*2 U^18 (F D)*2");
// => "R2 U2 F D F D"
Conjugates and commutators
normalize("[F: R]");
// => "F R F'"
normalize("[R, U]");
// => "R U R' U'"
normalize("[F: [R, U]]");
// => "F R U R' U' F'"
Obvious optimization
normalize("U4");
// => ""
normalize("U R4 U");
// => "U2"
normalize("R L R");
// => "R2 L"
API
normalize(algorithm[, options])
algorithm
Algorithm notation string to normalize.
options
Object with following format. All properties are optional.
{
separator: ' ',
useModifiers: true,
uniformCenterMoves: false, // false | 'rotation' | 'slice'
invert: false
}
separator
Separator string which will be inserted between each turns. (default ' '
)
useModifiers
If true
, returned notation includes modifier letters '
and 2
. If false
, inverted turns and half turns are represented as repetition. (default true
)
normalize("R' U2", { useModifiers: false });
// => "R R R U U"
uniformCenterMoves
If 'rotation'
or 'slice'
, turns with center moves (M
, x
, r
, etc.) are converted and unified to rotation moves (x
, y
and z
) or slice moves (M
, E
and S
). (default false
)
normalize("r E", { uniformCenterMoves: 'rotation' });
// => "L' x U D' y'"
normalize("r y", { uniformCenterMoves: 'slice' });
// => "R M' U D' E'"
Note: This center move conversion is only valid for 3x3x3 cube.
invert
If true
, algorithm will be inverted.
normalize("R U R' U'", { invert: true });
// => "U R U' R'"
This makes same result with normalize("(" + alg + ")'")
, but using this option will make messages of possible errors more clear especially for error location in algorithm string.
normalize.SyntaxError
PEG.js error class thrown from the parser.