Ignore imported style files when running in Node
Installations
npm install ignore-styles
Score
99.8
Supply Chain
99.4
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Developer
bkonkle
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
6.2.2
NPM Version
3.10.5
Statistics
211 Stars
62 Commits
16 Forks
3 Watching
1 Branches
10 Contributors
Updated on 25 Feb 2024
Bundle Size
819.00 B
Minified
475.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
46,618,675
Last day
-34.5%
18,120
Compared to previous day
Last week
-1.6%
134,403
Compared to previous week
Last month
10.4%
543,510
Compared to previous month
Last year
-28%
6,608,096
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
ignore-styles
A babel/register
style hook to ignore style imports when running in Node. This
is for projects that use something like Webpack to enable CSS imports in
JavaScript. When you try to run the project in Node (to test in Mocha, for
example) you'll see errors like this:
SyntaxError: /Users/brandon/code/my-project/src/components/my-component/style.sass: Unexpected token (1:0)
> 1 | .title
| ^
2 | font-family: serif
3 | font-size: 10em
4 |
To resolve this, require ignore-styles
with your mocha tests:
mocha --require ignore-styles
See DEFAULT_EXTENSIONS for the full list of extensions ignored, and send a pull request if you need more.
Note: This is not for use inside Webpack. If you want to ignore extensions in Webpack you'll want to use a loader like ignore-loader. This is for use in Node outside of your normal Webpack build.
Installation
$ npm install --save-dev ignore-styles
More Examples
To use this with multiple Mocha requires:
mocha --require babel-register --require ignore-styles
You can also use it just like babel/register
:
1import 'ignore-styles'
In ES5:
1require('ignore-styles')
To customize the extensions used:
1import register from 'ignore-styles' 2register(['.sass', '.scss'])
To customize the extensions in ES5:
1require('ignore-styles').default(['.sass', '.scss']);
Custom handler
By default, a no-op handler is used that doesn't actually do anything. If you'd like to substitute your own custom handler to do fancy things, pass it as a second argument:
1import register from 'ignore-styles' 2register(undefined, (module, filename) => { 3 module.exports = {styleName: 'fake_class_name'} 4})
The first argument to register
is the list of extensions to handle. Leaving it
undefined, as above, uses the default list. The handler function receives two arguments, module
and filename
, directly
from Node.
Why is this useful? One example is when using something like react-css-modules. You need the style imports to actually return something so that you can test the components, or the wrapper component will throw an error. Use this to provide test class names.
Another use case would be to simply return the filename of an image so that it can be verified in unit tests:
1const _ = require('lodash') 2const path = require('path') 3 4register(undefined, (module, filename) => { 5 if (_.some(['.png', '.jpg'], ext => filename.endsWith(ext))) { 6 module.exports = path.basename(filename) 7 } 8})
If the filename ends in '.png' or '.jpg', then the basename of the file is returned as the value of the module on import.
License
The MIT License (MIT)
Copyright (c) 2015 Brainspace Corporation
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 8/23 approved changesets -- score normalized to 3
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to ignore-styles
@types/ignore-styles
TypeScript definitions for ignore-styles
polished
A lightweight toolset for writing styles in Javascript.
ignore
Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.
ignore-by-default
A list of directories you should ignore by default