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

bedard-cube

v1.0.0

Published

[![Build](https://img.shields.io/circleci/project/github/scottbedard/cube.svg)](https://circleci.com/gh/scottbedard/cube) [![Coverage](https://img.shields.io/codecov/c/github/scottbedard/cube.svg)](https://codecov.io/gh/scottbedard/cube) [![License](https

Downloads

11

Readme

cube

Build Coverage Dependencies NPM License

This class models the state of Rubik's cubes. To get started, install the library through Yarn or NPM.

yarn add bedard-cube

# or

npm install bedard-cube

API

To instantiate a cube, use the Cube constructor and define the size of the cube. The size parameter must be an integer greater than 1.

// create a new 3x3 cube
const cube = new Cube(3);

To perform one or more turns to the cube, use the turn method. To manually convert a turn string to an object, use the parseTurn method.

// accepts a whitespace or comma seperated list of turns
cube.turn('F R- L');

The cube can be scrambled via the scramble function. This function optionally accepts a number of turns to perform. If omitted, the scramble depth will be determined by the size of the cube. Additionally, a scramble may be generated using the generateScramble function. The only difference between these two functions is that generateScramble does not perform the turns.

cube.scramble();

To test if the cube is solved, use the isSolved method. This function returns true or false.

cube.isSolved();

The cube can be returned to it's original state via the reset method.

cube.reset();

To itterate over all of the cube's stickers, use the stickers method.

cube.stickers(function(sticker) {
    // ...
});

State

To read the current state of the cube, access the state property. This property holds an object with properties for each face, each containing an array of sticker values. The face arrays start from the top left sticker and read sequentially to the bottom right. So for example, a newly instantiated 3x3 cube would have the following state.

{
    U: [
        0, 0, 0,
        0, 0, 0,
        0, 0, 0,
    ],
    L: [
        1, 1, 1,
        1, 1, 1,
        1, 1, 1,
    },
    F: [
        2, 2, 2,
        2, 2, 2,
        2, 2, 2,
    ],
    R: [
        3, 3, 3,
        3, 3, 3,
        3, 3, 3,
    ],
    B: [
        4, 4, 4,
        4, 4, 4,
        4, 4, 4,
    ],
    D: [
        5, 5, 5,
        5, 5, 5,
        5, 5, 5,
    ],
}

To picture how these values would map to an actual cube, imagine unfolding a cube while looking at the F face. Notice that the B face has the same orientation as the L, F, and R faces.

  U
L F R B
  D

To store additional data with the stickers, toggle the useObjects option. Setting this flag will store the sticker values as { originalIndex, value } objects. Note that the originalIndex key does not change as the cube is turned.

new Cube(size, { useObjects: true });

Notation

The notation system used by this library is a superset of WCA notation. Any algorithm produced by a WCA scrambler should be compatible with this library. There are however a couple of extensions we've made to the WCA syntax. The first of which being optional use of a - to indicate counter-clockwise turns. The second is the ability to annotate "slice turns" with a single move. To do this, simply omit the wide segment of a turn. For example, a 3F in our notation system would be equal to 3Fw 2Fw- in WCA notation.

License

MIT

Copyright (c) 2018-present, Scott Bedard