css-detective

1.0.0 • Public • Published

css-detective

Find all @imports by walking the AST (similar to and inspired by detective, but for CSS)

Build Status js-standard-style npm version Coverage Status

example

strings

style.css:

@import 'a';
@import 'b';
@import 'c';

strings.js:

var cssDetective = require('css-detective')
var fs = require('fs')
 
var src = fs.readFileSync(__dirname + '/style.css')
var imports = cssDetective(src)
console.dir(imports)

output:

$ node examples/strings.js
[ 'a', 'b', 'c' ]

methods

var cssDetective = require('css-detective')

cssDetective(src, opts)

Give some source body src, return an array of all the @imports.

The options parameter opts is passed along to cssDetective.find().

var found = cssDetective.find(src, opts)

Give some source body src, return found with:

  • found.strings - an array of each string found in an @import
  • found.nodes (when opts.nodes === true) - an array of AST nodes for each argument found in an @import

Optionally:

  • opts.nodes - when true, populate found.nodes
  • opts.isImport(node) - a function returning whether an AST node is an import
  • opts.parse - supply options directly to postcss

install

With npm do:

npm install css-detective

license

ISC

/css-detective/

    Package Sidebar

    Install

    npm i css-detective

    Weekly Downloads

    0

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • vigour-io