Book Image

LESS WEB DEVELOPMENT COOKBOOK

Book Image

LESS WEB DEVELOPMENT COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Less Web Development Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Evaluating the type of a value


The built-in functions are grouped as the type functions that can be used to evaluate the type of a value. The result can be used to match mixins based on the value type.

Getting ready

For this recipe, you will need a text editor and the command-line lessc compiler ready, as described in the Installing the lessc compiler with npm recipe in Chapter 1, Getting to Grips with the Basics of Less.

How to do it…

  1. Write the following code into a Less file and compile this file with the command-line lessc compiler:

    color-tstt(@color,@test-number) when (iscolor(@color))
    {
      result-@{test-number}: %("%a is a color",@color);
    }
    .color-test(@color,@test-number) when (default())
    {
      result-@{test-number}: %("%a is Not a color",@color);
    }
    test {
      .color-test(blue,1);
      .color-test("blue",2);
      .color-test(color("blue"),3);
      .color-test(~"blue",4);
    }
  2. The preceding Less code will compile into the following CSS code:

    test {
      result-1: "#0000ff is a color";
      result-2: ""blue" is Not...