npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cube-notation-normalizer

v1.0.0

Published

Parse and "normalize" Rubik's Cube algorithm notations

Downloads

47

Readme

cube-notation-normalizer

Build Status Coverage Status npm

There are several number of rubik's cube related programs on npm, and many of them has their own functions to parse algorithms. Mostly their functions support only limited syntax of algorithm notation unfortunately.

This library intends to be a base for this kind of programs to support broad syntax of algorithm notation.

The syntax definition is written by and the parser is generated by PEG.js.

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'"

// program-friendly format
normalize(ugly, {
  separator: '',
  useModifiers: false,
  uniformCenterMoves: 'slice'
});
// => "RMMMURRRUUURRRMFRFFF"

With the latter options, result will contain only R, U, F, L, D, B, M, E and S letters and not contain any whitespaces nor modifiers. This is highly well-formatted and will be very handy for programs. Especially, .split('') or .match(/(.)\1*/g) may be useful.

If you prefer, you also can choose x, y and z instead of M, E and S.

Supported syntax and features

Face turns, slice turns and cube rotations

// supported face letters:
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

// 'w' notation is normalized to lowercase
normalize("r Uw");
// => "r u"

Whitespaces and comments

normalize(`
R        (U)
R'U' // sexy move
/*
R' F R F'
*/
`);
// => "R U R' U'"

Invert

// variety of "prime"s
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', the 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("y r", { uniformCenterMoves: 'slice' });
// => "U D' E' R M'"

Note: This center move conversion is valid for only 3x3x3 cube.

invert

If true, algorithm will be inverted. (default false)

normalize("R U R' U'", { invert: true });
// => "U R U' R'"

This returns same result as normalize("(" + alg + ")'"), but using this option will make messages of possible errors more clear, especially for error location in algorithm strings.

normalize.SyntaxError

PEG.js error class thrown from the parser.