Skip to content

vigour-io/css-detective

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'] }

About

Find all `@import`s by walking the AST

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published