Giter Club home page Giter Club logo

postcss-selector-source's Introduction

postcss-selector-source

A PostCSS plugin for finding the original line and column position of your CSS selectors and declarations from your pre-processed SASS/SCSS/LESS/Stylus files.

Installation

npm install --save postcss-selector-source

Usage

This plugin doesn't edit your css, it returns an object of all of your used selectors and declarations with pointers to their original position.

var postcss = require('postcss');
var selectorSource = require('postcss-selector-source');

postcss([
  selectorSource({
    cssRootDir: './path/to/css/',
    function(selectors) {
      console.log(selectors);
  }})
]).process(css);

Don't want to include all of your CSS?

Anything declared above this comment won't show up in the results.

@import 'bootstrap'; // won't be included
@import 'wont-be-included'; // won't be included
/* !ATTN - anything above me won't be included */
@import 'will-be-included';

.will-also-be-included {
}

Sample output

[
  {
    "selector": ".first-selector",
    "selectors": [".first-selector"],
    "specificity": 10,
    "decls": [{
      "property": "content",
      "value": "'first selector'",
      "important": false,
      "start": {
        "line": 6,
        "column": 3
      },
      "end": {
        "line": 6,
        "column": 28
      },
      "originalPosition": {
        "start": {
          "source": "src/test.scss",
          "line": 7,
          "column": 2,
          "name": null
        },
        "end": {
          "source": "src/test.scss",
          "line": 7,
          "column": 28,
          "name": null
        }
      }
    }, {
      "property": "color",
      "value": "#ffffff",
      "important": true,
      "start": {
        "line": 7,
        "column": 3
      },
      "end": {
        "line": 7,
        "column": 28
      },
      "originalPosition": {
        "start": {
          "source": "src/test.scss",
          "line": 8,
          "column": 2,
          "name": null
        },
        "end": {
          "source": "src/test.scss",
          "line": 8,
          "column": 35,
          "name": null
        }
      }
    }],
    "start": {
      "line": 5,
      "column": 1
    },
    "end": {
      "line": 7,
      "column": 30
    },
    "originalPosition": {
      "start": {
        "source": "src/test.scss",
        "line": 6,
        "column": 0,
        "name": null
      },
      "end": {
        "source": "src/test.scss",
        "line": 6,
        "column": 17,
        "name": null
      }
    }
  }, {
    "selector": ".first-selector",
    "selectors": [".first-selector"],
    "specificity": 10,
    "decls": [{
      "property": "content",
      "value": "'first selector media query'",
      "important": false,
      "start": {
        "line": 10,
        "column": 7
      },
      "end": {
        "line": 10,
        "column": 44
      },
      "originalPosition": {
        "start": {
          "source": "src/test.scss",
          "line": 11,
          "column": 4,
          "name": null
        },
        "end": {
          "source": "src/test.scss",
          "line": 11,
          "column": 42,
          "name": null
        }
      }
    }, {
      "property": "width",
      "value": "500px",
      "important": false,
      "start": {
        "line": 11,
        "column": 7
      },
      "end": {
        "line": 11,
        "column": 19
      },
      "originalPosition": {
        "start": {
          "source": "src/test.scss",
          "line": 12,
          "column": 4,
          "name": null
        },
        "end": {
          "source": "src/_variable-includes.scss",
          "line": 2,
          "column": 21,
          "name": null
        }
      }
    }],
    "start": {
      "line": 9,
      "column": 5
    },
    "end": {
      "line": 11,
      "column": 21
    },
    "params": [{
      "property": "max-width",
      "value": "300px"
    }],
    "originalPosition": {
      "start": {
        "source": "src/test.scss",
        "line": 6,
        "column": 0,
        "name": null
      },
      "end": {
        "source": "src/test.scss",
        "line": 6,
        "column": 17,
        "name": null
      }
    }
  }
...
]

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.