Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulmelnikow/chainsmoker
Elegant, generically typed, boolean micromatch for lists of file paths
https://github.com/paulmelnikow/chainsmoker
filematch keyed-paths micromatch minimatch path-matching typescript
Last synced: 2 days ago
JSON representation
Elegant, generically typed, boolean micromatch for lists of file paths
- Host: GitHub
- URL: https://github.com/paulmelnikow/chainsmoker
- Owner: paulmelnikow
- License: mit
- Created: 2017-12-07T02:57:11.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T02:59:00.000Z (almost 2 years ago)
- Last Synced: 2024-12-29T06:10:22.457Z (5 days ago)
- Topics: filematch, keyed-paths, micromatch, minimatch, path-matching, typescript
- Language: TypeScript
- Homepage:
- Size: 2.24 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# chainsmoker
[![version](https://img.shields.io/npm/v/chainsmoker.svg?style=flat-square)][npm]
[![license](https://img.shields.io/npm/l/chainsmoker.svg?style=flat-square)][npm]
[![types](https://img.shields.io/npm/types/chainsmoker.svg?style=flat-square)][npm]
[![build](https://img.shields.io/circleci/project/github/paulmelnikow/chainsmoker.svg?style=flat-square)][build]
[![code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)][prettier][npm]: https://npmjs.com/chainsmoker/
[build]: https://circleci.com/gh/paulmelnikow/chainsmoker/tree/master
[prettier]: https://prettier.io/
[lerna]: https://lernajs.io/Elegant, generically typed, boolean [micromatch][] for lists of file paths in
TypeScript.- Works with CommonJS and ES Modules, too.
- Safer and more concise than using `.filter()` and `.length`.
- Designed for concise syntax in [dangerfiles][danger] but not tied to them in
any way.I'm pleased to say as of [Danger.js 7.1][danger], this helper is vendored into
Danger and accessible as `danger.fileMatch`.[micromatch]: https://github.com/micromatch/micromatch
[danger]: http://danger.systems/js/## Usage
```js
const { danger, fail, message, warn } = require('danger')
const chainsmoker = require('chainsmoker')// In this example, these are all arrays of relative paths.
const fileMatch = chainsmoker({
created: danger.git.created_files,
modified: danger.git.modified_files,
updated: danger.git.modified_files.concat(danger.git.created_files),
deleted: danger.git.deleted_files,
})const documentation = fileMatch(
'**/*.md',
'lib/all-badge-examples.js',
'frontend/components/usage.js'
)
const packageJson = fileMatch('package.json')
const packageLock = fileMatch('package-lock.json')
const helpers = fileMatch('lib/**/*.js', '!**.spec.js')
const helperTests = fileMatch('lib/**/*.spec.js')// This is `true` whenever there are matches in the corresponding path array.
if (documentation.updated) {
message('We :heart: our [documentarians](http://www.writethedocs.org/)!')
}if (packageJson.modified && !packageLock.modified) {
warn('This PR modified package.json, but not package-lock.json')
}if (helpers.created && !helperTests.created) {
warn('This PR added helper modules in lib/ but not accompanying tests.')
} else if (helpers.updated && !helperTests.updated) {
warn('This PR modified helper modules in lib/ but not accompanying tests.')
}
```**fileMatch.getKeyedPatterns()**
Return an object containing arrays of matched files instead of the usual
boolean values.## Installation
Requires Node 8+.
```
npm install --save-dev chainsmoker
```## Contribute
- Issue Tracker: https://github.com/paulmelnikow/chainsmoker/issues
- Source Code: https://github.com/paulmelnikow/chainsmokerPull requests welcome!
## Support
If you are having issues, please let me know.
## The name :smoking:
The name was inspired by the idea of a chainable file-set object using
minimatch. It's also for Danger… maybe that was part of the inspiration.I ended up with something simpler that doesn't rely on chaining, though I kept
the name.## Acknowledgements
Thanks to [@orta][] for reviewing this and shipping it with Danger.
[@orta]: http://github.com/orta
## License
The project is licensed under the MIT license.