Giter VIP home page Giter VIP logo

ocss-parser's Introduction

ocss-parser

version build

syntax parser for the OCSS preprocessor

Example Input

display: block
color: red

child
  color: blue
  background: transparent

  :hover
    color: red

  subchild
    font-size: 12px

=big
  font-size: 200%

  child
    color: red

^highlight
  border: 1px solid red

  child
    padding: 2em

    subchild
      color: yellow

Example Output

{
  "type": "object",
  "name": "test",
  "declarations": [
    {
      "position": {
        "line": 1
      },
      "type": "declaration",
      "property": "display",
      "value": "block"
    },
    {
      "position": {
        "line": 2
      },
      "type": "declaration",
      "property": "color",
      "value": "red"
    }
  ],
  "elements": [
    {
      "position": {
        "line": 4
      },
      "type": "element",
      "name": "child",
      "declarations": [
        {
          "position": {
            "line": 5
          },
          "type": "declaration",
          "property": "color",
          "value": "blue"
        },
        {
          "position": {
            "line": 6
          },
          "type": "declaration",
          "property": "background",
          "value": "transparent"
        }
      ],
      "pseudoelements": [
        {
          "position": {
            "line": 8
          },
          "type": "pseudoelement",
          "name": "hover",
          "declarations": [
            {
              "position": {
                "line": 9
              },
              "type": "declaration",
              "property": "color",
              "value": "red"
            }
          ]
        }
      ],
      "elements": [
        {
          "position": {
            "line": 11
          },
          "type": "element",
          "name": "subchild",
          "declarations": [
            {
              "position": {
                "line": 12
              },
              "type": "declaration",
              "property": "font-size",
              "value": "12px"
            }
          ]
        }
      ]
    }
  ],
  "modifiers": [
    {
      "position": {
        "line": 14
      },
      "type": "modifier",
      "name": "big",
      "declarations": [
        {
          "position": {
            "line": 15
          },
          "type": "declaration",
          "property": "font-size",
          "value": "200%"
        }
      ],
      "elements": [
        {
          "position": {
            "line": 17
          },
          "type": "element",
          "name": "child",
          "declarations": [
            {
              "position": {
                "line": 18
              },
              "type": "declaration",
              "property": "color",
              "value": "red"
            }
          ]
        }
      ]
    }
  ],
  "parentmodifiers": [
    {
      "position": {
        "line": 20
      },
      "type": "parentmodifier",
      "name": "highlight",
      "declarations": [
        {
          "position": {
            "line": 21
          },
          "type": "declaration",
          "property": "border",
          "value": "1px solid red"
        }
      ],
      "elements": [
        {
          "position": {
            "line": 23
          },
          "type": "element",
          "name": "child",
          "declarations": [
            {
              "position": {
                "line": 24
              },
              "type": "declaration",
              "property": "padding",
              "value": "2em"
            }
          ],
          "elements": [
            {
              "position": {
                "line": 26
              },
              "type": "element",
              "name": "subchild",
              "declarations": [
                {
                  "position": {
                    "line": 27
                  },
                  "type": "declaration",
                  "property": "color",
                  "value": "yellow"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Tests

Install dependencies with npm install once. Afterwards run npm test every time you want to start the tests.

ocss-parser's People

Watchers

 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.