Find all @import
s 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.
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']
-
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
, populatesfound.nodes
- opts.nodes (boolean) - when
-
- opts.parse (object) - options to provide directly to
-
returns (object) found - returns
found
with: -
- found.strings (array) - each string found in an
@import
- found.strings (array) - each string found in an
-
- found.nodes (array|undefined) - AST
@import
nodes found ifopts.nodes === true
,undefined
otherwise
- found.nodes (array|undefined) - AST
var cssDetective = require('css-detective')
cssDetective.find('@import "a";\n@import "b";')
// { strings: ['a', 'b'] }