pax_global_header00006660000000000000000000000064136052756360014527gustar00rootroot0000000000000052 comment=78843a5fea53a838d784743bde4c9470e50a9930 dotignore-0.1.2/000077500000000000000000000000001360527563600135215ustar00rootroot00000000000000dotignore-0.1.2/.eslintrc000066400000000000000000000005761360527563600153550ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "func-name-matching": [2, "always"], "func-style": 1, "indent": [2, 2], "max-statements": 0, "no-loop-func": 1, "no-param-reassign": 1, }, "overrides": [ { "files": "bin/**", "env": { "node": true, }, "rules": { "no-console": 0, }, }, ], } dotignore-0.1.2/.gitignore000066400000000000000000000001411360527563600155050ustar00rootroot00000000000000node_modules/ # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock dotignore-0.1.2/.npmrc000066400000000000000000000000231360527563600146340ustar00rootroot00000000000000package-lock=false dotignore-0.1.2/README.md000066400000000000000000000011031360527563600147730ustar00rootroot00000000000000# dotignore ## `ignored $IGNOREFILE` Check the ignorefile against the current directory. Print out if a file should be ignored by prefixing with a `-`. If the file should not be ignored prefix it with a `+`. ## API ### exports.createMatcher(str) Return a `Matcher` that fully matches the `str` argument. `str` should conform to the `.gitignore` specification. ### Matcher.shouldIgnore(name) Test that all the rules provided to create the matcher match the name given. `/` is expected as the path delimiter. Returns `true` if the name should be ignored. ## LICENSE MIT dotignore-0.1.2/bin/000077500000000000000000000000001360527563600142715ustar00rootroot00000000000000dotignore-0.1.2/bin/ignored000077500000000000000000000010711360527563600156450ustar00rootroot00000000000000#!/usr/bin/env node 'use strict'; var fs = require('fs'); var path = require('path'); var rules = String(fs.readFileSync(process.argv[2] || '.gitignore')); var matcher = require('../').createMatcher(rules); function checkDir(dir) { fs.readdirSync(dir).forEach(function (filename) { var resolved = path.join(dir, filename); if (matcher.shouldIgnore(resolved)) { console.log('- ' + resolved); } else if (fs.statSync(resolved).isDirectory()) { checkDir(resolved); } else { console.log('+ ' + resolved); } }); } checkDir('.'); dotignore-0.1.2/index.js000066400000000000000000000027251360527563600151740ustar00rootroot00000000000000'use strict'; var minimatch = require('minimatch'); var path = require('path'); function IgnoreMatcher(str) { var negated = []; this.negated = negated; var rooted = []; this.rooted = rooted; this.matchers = str.split(/\r?\n|\r/).map(function (line) { var negatedLine = line[0] === '!'; var commentLine = line[0] === '#'; var rootedLine = line[0] === '/'; if (negatedLine || commentLine || rootedLine) { line = line.slice(1); } var emptyLine = line === ''; if (emptyLine) { return null; } var isShellGlob = line.indexOf('/') >= 0; negated[negated.length] = negatedLine; rooted[rooted.length] = rootedLine || isShellGlob; return minimatch.makeRe(line, { comment: commentLine, empty: emptyLine, matchBase: !rootedLine, negated: true // negated }); }).filter(Boolean); return this; } IgnoreMatcher.prototype.delimiter = path.sep; IgnoreMatcher.prototype.shouldIgnore = function (filename) { var isMatching = false; for (var i = 0; i < this.matchers.length; i++) { var matcher = this.matchers[i]; if (this.rooted[i]) { if (matcher.test(filename)) { isMatching = !this.negated[i]; } } else if (filename.split(this.delimiter).some(function (part) { return matcher.test(part); })) { isMatching = !this.negated[i]; } } return isMatching; }; exports.createMatcher = function (ignoreFileStr) { return new IgnoreMatcher(ignoreFileStr); }; dotignore-0.1.2/package.json000066400000000000000000000015531360527563600160130ustar00rootroot00000000000000{ "name": "dotignore", "version": "0.1.2", "description": "ignorefile/includefile matching .gitignore spec", "main": "index.js", "bin": { "ignored": "bin/ignored" }, "scripts": { "prepublish": "safe-publish-latest", "pretest": "npm run lint", "test": "node test && npm run coverage -- --quiet", "coverage": "covert test/index.js", "lint": "eslint bin/* ." }, "repository": { "type": "git", "url": "http://github.com/bmeck/dotignore" }, "keywords": [ "ignore", "gitignore", "npmignore", "glob", "pattern" ], "author": { "name": "bradleymeck" }, "license": "MIT", "dependencies": { "minimatch": "^3.0.4" }, "devDependencies": { "@ljharb/eslint-config": "^15.1.0", "covert": "^1.1.1", "eslint": "^6.8.0", "safe-publish-latest": "^1.1.4", "tape": "^4.12.1" } } dotignore-0.1.2/test/000077500000000000000000000000001360527563600145005ustar00rootroot00000000000000dotignore-0.1.2/test/.1-ignore000066400000000000000000000000211360527563600161130ustar00rootroot00000000000000*ignored !a/not* dotignore-0.1.2/test/1-expected000066400000000000000000000001311360527563600163550ustar00rootroot00000000000000+ .ignore - a/a/notignored - a/ignored + a/notignored + a/notlisted + expected + test.js dotignore-0.1.2/test/index.js000066400000000000000000000023351360527563600161500ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var path = require('path'); var rules = String(fs.readFileSync(path.join(process.cwd(), 'test', '.1-ignore'))); var matcher = require('../').createMatcher(rules); var test = require('tape'); var checkDir = function checkDir(dir, paths, output) { if (!output) { output = ''; } paths.forEach(function (pathArr) { var isDir = Array.isArray(pathArr); var filename = isDir ? pathArr[0] : pathArr; var resolved = path.join(dir, filename); if (matcher.shouldIgnore(resolved)) { output += '- ' + resolved + '\n'; } else if (isDir) { output = checkDir(resolved, pathArr[1], output); } else { output += '+ ' + resolved + '\n'; } }); return output; }; test('expected output', function (t) { process.chdir(path.join(process.cwd(), 'test')); var root = [ '.ignore', [ 'a', [ ['a', ['notignored']], 'ignored', 'notignored', 'notlisted' ] ], 'expected', 'test.js' ]; var output = checkDir('.', root); t.equal(output, String(fs.readFileSync('1-expected'))); t.end(); }); test('delimiter defaults to path.sep', function (t) { t.equal(matcher.delimiter, path.sep); t.end(); });