Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 2.47 KB

README.md

File metadata and controls

58 lines (41 loc) · 2.47 KB

Build Status js-standard-style npm version Coverage Status

css-detective

Find all @imports by walking the AST

Similar to, and inspired by detective. Uses postcss to parse the CSS into an abstract syntax tree (AST), so some level of invalid CSS is supported.

var strings = cssDetective(src, opts)

  • src (string) - Same as src parameter of find
  • opts (object) - Same as opts parameter of find

Same as require('css-detective').find(src, opts).strings

See find below

var cssDetective = require('css-detective')
cssDetective('@import "a";\n@import "b";')
// ['a', 'b']

var found = find(src, [opts])

  • src (string) - Source css body (anything postcss can parse). Can be a string or anything with a toString method

  • [opts] (object) - An object with any of the following options:

    • opts.nodes (boolean) - when true, populates found.nodes
    • opts.parse (object) - options to provide directly to

postcss's parse method

  • returns (object) found - returns found with:

    • found.strings (array) - each string found in an @import
    • found.nodes (array|undefined) - AST @import nodes found if opts.nodes === true, undefined otherwise
var cssDetective = require('css-detective')
cssDetective.find('@import "a";\n@import "b";')
// { strings: ['a', 'b'] }