Giter VIP home page Giter VIP logo

css-expression's Introduction

Usage

$ npm install css-expression

Parse CSS Expression

import { parse } from 'css-expression'

// Simple example
const expr1 = parse('linear-gradient(90deg, #f00 0%, #000 100%)');

// Complex example
const expr2 = parse('10px ((((800)))) hui(200, 500, rgba(400, 20, 55, 0.5), dont(trust(23, 42, verify), 10000)) (100 (foo bar gay vibes( ss, 10px)) 200 30)  100% hahah was    geht 1.6em 2   /  span 1  ');

Stringify CSS Expression

import { stringify } from 'css-expression'

// Simple example
const str1 = (stringify({
  type: 'function',
  name: 'rgb',
  args: [
    { type: 'primitive', value: 255, unit: null },
    { type: 'primitive', value: 0, unit: null },
    { type: 'primitive', value: 138, unit: null }
  ]
}); // => rgb(255, 0, 138)

// Complex example
const str2 = stringify({
  type: 'expression',
  literals: [
    {
      type: 'function',
      name: 'holy',
      args: [
        {
          type: 'expression',
          literals: [
            { type: 'primitive', value: 'fucking', unit: null },
            { type: 'primitive', value: 99, unit: 'px' }
          ]
        },
        {
          type: 'function',
          name: 'bee',
          args: [
            {
              type: 'expression',
              literals: [
                { type: 'primitive', value: 42, unit: '%' },
                { type: 'primitive', value: 'cool', unit: null }
              ]
            },
            { type: 'primitive', value: 'funny', unit: null }
          ]
        }
      ]
    },
    {
      type: 'expression',
      literals: [
        { type: 'primitive', value: 'all', unit: null },
        { type: 'primitive', value: 'good', unit: null },
        { type: 'primitive', value: 20, unit: 'em' }
      ]
    }
  ]
}); // => holy(fucking 99px, bee(42% cool, funny)) (all good 20em)

css-expression's People

Contributors

mauriceconrad avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.