Code Monkey home page Code Monkey logo

sassycast's Introduction

SassyCast

SassyCast is a simple API for type conversion in Sass. Read API documentation.

Installation

Clone repository or download from Github.

Install via ruby gems

gem install SassyCast

Install via bower

bower install sassy-cast

to-bool

to-bool(false);                 // false
to-bool(0);                     // false
to-bool(null);                  // false
to-bool("");                    // false
to-bool(true);                  // true
to-bool(1);                     // true
to-bool(());                    // true
to-bool(string);                // true
to-bool("quoted string");       // true
to-bool(this is a list);        // true
to-bool((this: is a map));      // true
to-bool(1337);                  // true
to-bool(#000);                  // true

to-number

to-number(1337);                // 1337
to-number("0");                 // 0
to-number("42");                // 42
to-number("4.2");               // 4.2
to-number("-10");               // -10
to-number("-10px");             // -10px
to-number(true);                // 1
to-number(false);               // 0
to-number(string);              // 0
to-number(this is a list);      // 0
to-number((this: is a map));    // 0
to-number(null);                // 0
to-number(#000);                // 0

to-list

to-list(0);                     // 0
to-list(1);                     // 1
to-list(string);                // string
to-list(this is a list);        // this is a list
to-list(this: is a map);        // this, is a map
to-list(true);                  // true
to-list(false);                 // false
to-list(null);                  // null
to-list(#000);                  // #333

to-string

to-string(0);                   // "0"
to-string(1);                   // "1"
to-string(true);                // "true"
to-string(false);               // "false"
to-string(null);                // "null"
to-string(this is a list);      // "this is a list"
to-string(this, is, a, list);   // "this, is, a, list"
to-string((this: is a map));    // "(this: is a map)"
to-string((this: is, a, map));  // "(this: is, a, map)"
to-string(#000);                // "#333"

to-null

to-null(null);                  // null
to-null(0);                     // null
to-null(1);                     // null
to-null(string);                // null
to-null(this is a list);        // null
to-null(this: is a map);        // null
to-null(true);                  // null
to-null(false);                 // null
to-null(#333);                  // null

to-map

to-map(0);                      // (1: 0)
to-map(1);                      // (1: 1)
to-map(true);                   // (1: true)
to-map(false);                  // (1: false)
to-map(null);                   // (1: null)
to-map(string);                 // (1: string)
to-map(this is a list);         // (1: this, 2: is, 3: a, 4: map)
to-map(this: is a map);         // (this: is a map)

to-color

to-color(0);                    // null
to-color(1);                    // null
to-color(black);                // black
to-color(#000);                 // black
to-color("#000");               // black
to-color(true);                 // null
to-color(false);                // null
to-color(null);                 // null
to-color(string);               // null
to-color(this is a list);       // null
to-color((this: is a map));     // null

A few things to note:

  • When trying to cast something to a number that cannot be converted, it returns 0
  • When trying to cast something to a color that cannot be converted, it returns null
  • Casting to a map use 1 as key (and index in case of a list)
  • Color formats are sometimes converted automatically by Sass; when casting a color to string, the resulting string can be different from the color input

Credits

Huge thanks to Marc Mintel for his help.

sassycast's People

Contributors

kittygiraudel avatar mmintel avatar

Watchers

James Cloos avatar Brandon Sarà avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.