2.3.18 • Published 1 year ago

@devtea2027/maxime-explicabo-consequuntur-eligendi v2.3.18

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@devtea2027/maxime-explicabo-consequuntur-eligendi

@devtea2027/maxime-explicabo-consequuntur-eligendi is a manager, filter and parser which implemented in pure JavaScript according to the .git@devtea2027/maxime-explicabo-consequuntur-eligendi spec 2.22.1.

@devtea2027/maxime-explicabo-consequuntur-eligendi is used by eslint, gitbook and many others.

Pay ATTENTION that minimatch (which used by fstream-@devtea2027/maxime-explicabo-consequuntur-eligendi) does not follow the git@devtea2027/maxime-explicabo-consequuntur-eligendi spec.

To filter filenames according to a .git@devtea2027/maxime-explicabo-consequuntur-eligendi file, I recommend this npm package, @devtea2027/maxime-explicabo-consequuntur-eligendi.

To parse an .npm@devtea2027/maxime-explicabo-consequuntur-eligendi file, you should use minimatch, because an .npm@devtea2027/maxime-explicabo-consequuntur-eligendi file is parsed by npm using minimatch and it does not work in the .git@devtea2027/maxime-explicabo-consequuntur-eligendi way.

Tested on

@devtea2027/maxime-explicabo-consequuntur-eligendi is fully tested, and has more than five hundreds of unit tests.

  • Linux + Node: 0.8 - 7.x
  • Windows + Node: 0.10 - 7.x, node < 0.10 is not tested due to the lack of support of appveyor.

Actually, @devtea2027/maxime-explicabo-consequuntur-eligendi does not rely on any versions of node specially.

Since 4.0.0, @devtea2027/maxime-explicabo-consequuntur-eligendi will no longer support node < 6 by default, to use in node < 6, require('@devtea2027/maxime-explicabo-consequuntur-eligendi/legacy'). For details, see CHANGELOG.

Table Of Main Contents

Install

npm i @devtea2027/maxime-explicabo-consequuntur-eligendi

Usage

import @devtea2027/maxime-explicabo-consequuntur-eligendi from '@devtea2027/maxime-explicabo-consequuntur-eligendi'
const ig = @devtea2027/maxime-explicabo-consequuntur-eligendi().add(['.abc/*', '!.abc/d/'])

Filter the given paths

const paths = [
  '.abc/a.js',    // filtered out
  '.abc/d/e.js'   // included
]

ig.filter(paths)        // ['.abc/d/e.js']
ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('.abc/a.js') // true

As the filter function

paths.filter(ig.createFilter()); // ['.abc/d/e.js']

Win32 paths will be handled

ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])
// if the code above runs on windows, the result will be
// ['.abc\\d\\e.js']

Why another @devtea2027/maxime-explicabo-consequuntur-eligendi?

  • @devtea2027/maxime-explicabo-consequuntur-eligendi is a standalone module, and is much simpler so that it could easy work with other programs, unlike isaacs's fstream-@devtea2027/maxime-explicabo-consequuntur-eligendi which must work with the modules of the fstream family.

  • @devtea2027/maxime-explicabo-consequuntur-eligendi only contains utility methods to filter paths according to the specified @devtea2027/maxime-explicabo-consequuntur-eligendi rules, so

    • @devtea2027/maxime-explicabo-consequuntur-eligendi never try to find out @devtea2027/maxime-explicabo-consequuntur-eligendi rules by traversing directories or fetching from git configurations.
    • @devtea2027/maxime-explicabo-consequuntur-eligendi don't cares about sub-modules of git projects.
  • Exactly according to git@devtea2027/maxime-explicabo-consequuntur-eligendi man page, fixes some known matching issues of fstream-@devtea2027/maxime-explicabo-consequuntur-eligendi, such as:

    • '/*.js' should only match 'a.js', but not 'abc/a.js'.
    • '**/foo' should match 'foo' anywhere.
    • Prevent re-including a file if a parent directory of that file is excluded.
    • Handle trailing whitespaces:
      • 'a '(one space) should not match 'a '(two spaces).
      • 'a \ ' matches 'a '
    • All test cases are verified with the result of git check-@devtea2027/maxime-explicabo-consequuntur-eligendi.

Methods

.add(pattern: string | Ignore): this

.add(patterns: Array<string | Ignore>): this

  • pattern String | Ignore An @devtea2027/maxime-explicabo-consequuntur-eligendi pattern string, or the Ignore instance
  • patterns Array<String | Ignore> Array of @devtea2027/maxime-explicabo-consequuntur-eligendi patterns.

Adds a rule or several rules to the current manager.

Returns this

Notice that a line starting with '#'(hash) is treated as a comment. Put a backslash ('\') in front of the first hash for patterns that begin with a hash, if you want to @devtea2027/maxime-explicabo-consequuntur-eligendi a file with a hash at the beginning of the filename.

@devtea2027/maxime-explicabo-consequuntur-eligendi().add('#abc').@devtea2027/maxime-explicabo-consequuntur-eligendis('#abc')    // false
@devtea2027/maxime-explicabo-consequuntur-eligendi().add('\\#abc').@devtea2027/maxime-explicabo-consequuntur-eligendis('#abc')   // true

pattern could either be a line of @devtea2027/maxime-explicabo-consequuntur-eligendi pattern or a string of multiple @devtea2027/maxime-explicabo-consequuntur-eligendi patterns, which means we could just @devtea2027/maxime-explicabo-consequuntur-eligendi().add() the content of a @devtea2027/maxime-explicabo-consequuntur-eligendi file:

@devtea2027/maxime-explicabo-consequuntur-eligendi()
.add(fs.readFileSync(filenameOfGit@devtea2027/maxime-explicabo-consequuntur-eligendi).toString())
.filter(filenames)

pattern could also be an @devtea2027/maxime-explicabo-consequuntur-eligendi instance, so that we could easily inherit the rules of another Ignore instance.

.addIgnoreFile(path)

REMOVED in 3.x for now.

To upgrade @devtea2027/maxime-explicabo-consequuntur-eligendi@2.x up to 3.x, use

import fs from 'fs'

if (fs.existsSync(filename)) {
  @devtea2027/maxime-explicabo-consequuntur-eligendi().add(fs.readFileSync(filename).toString())
}

instead.

.filter(paths: Array<Pathname>): Array<Pathname>

type Pathname = string

Filters the given array of pathnames, and returns the filtered array.

  • paths Array.<Pathname> The array of pathnames to be filtered.

Pathname Conventions:

1. Pathname should be a path.relative()d pathname

Pathname should be a string that have been path.join()ed, or the return value of path.relative() to the current directory,

// WRONG, an error will be thrown
ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('./abc')

// WRONG, for it will never happen, and an error will be thrown
// If the git@devtea2027/maxime-explicabo-consequuntur-eligendi rule locates at the root directory,
// `'/abc'` should be changed to `'abc'`.
// ```
// path.relative('/', '/abc')  -> 'abc'
// ```
ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('/abc')

// WRONG, that it is an absolute path on Windows, an error will be thrown
ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('C:\\abc')

// Right
ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('abc')

// Right
ig.@devtea2027/maxime-explicabo-consequuntur-eligendis(path.join('./abc'))  // path.join('./abc') -> 'abc'

In other words, each Pathname here should be a relative path to the directory of the git@devtea2027/maxime-explicabo-consequuntur-eligendi rules.

Suppose the dir structure is:

/path/to/your/repo
    |-- a
    |   |-- a.js
    |
    |-- .b
    |
    |-- .c
         |-- .DS_store

Then the paths might be like this:

[
  'a/a.js'
  '.b',
  '.c/.DS_store'
]

2. filenames and dirnames

node-@devtea2027/maxime-explicabo-consequuntur-eligendi does NO fs.stat during path matching, so for the example below:

// First, we add a @devtea2027/maxime-explicabo-consequuntur-eligendi pattern to @devtea2027/maxime-explicabo-consequuntur-eligendi a directory
ig.add('config/')

// `ig` does NOT know if 'config', in the real world,
//   is a normal file, directory or something.

ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('config')
// `ig` treats `config` as a file, so it returns `false`

ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('config/')
// returns `true`

Specially for people who develop some library based on node-@devtea2027/maxime-explicabo-consequuntur-eligendi, it is important to understand that.

Usually, you could use glob with option.mark = true to fetch the structure of the current directory:

import glob from 'glob'

glob('**', {
  // Adds a / character to directory matches.
  mark: true
}, (err, files) => {
  if (err) {
    return console.error(err)
  }

  let filtered = @devtea2027/maxime-explicabo-consequuntur-eligendi().add(patterns).filter(files)
  console.log(filtered)
})

.@devtea2027/maxime-explicabo-consequuntur-eligendis(pathname: Pathname): boolean

new in 3.2.0

Returns Boolean whether pathname should be @devtea2027/maxime-explicabo-consequuntur-eligendid.

ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('.abc/a.js')    // true

.createFilter()

Creates a filter function which could filter an array of paths with Array.prototype.filter.

Returns function(path) the filter function.

.test(pathname: Pathname) since 5.0.0

Returns TestResult

interface TestResult {
  @devtea2027/maxime-explicabo-consequuntur-eligendid: boolean
  // true if the `pathname` is finally un@devtea2027/maxime-explicabo-consequuntur-eligendid by some negative pattern
  un@devtea2027/maxime-explicabo-consequuntur-eligendid: boolean
}
  • {@devtea2027/maxime-explicabo-consequuntur-eligendid: true, un@devtea2027/maxime-explicabo-consequuntur-eligendid: false}: the pathname is @devtea2027/maxime-explicabo-consequuntur-eligendid
  • {@devtea2027/maxime-explicabo-consequuntur-eligendid: false, un@devtea2027/maxime-explicabo-consequuntur-eligendid: true}: the pathname is un@devtea2027/maxime-explicabo-consequuntur-eligendid
  • {@devtea2027/maxime-explicabo-consequuntur-eligendid: false, un@devtea2027/maxime-explicabo-consequuntur-eligendid: false}: the pathname is never matched by any @devtea2027/maxime-explicabo-consequuntur-eligendi rules.

static @devtea2027/maxime-explicabo-consequuntur-eligendi.isPathValid(pathname): boolean since 5.0.0

Check whether the pathname is an valid path.relative()d path according to the convention.

This method is NOT used to check if an @devtea2027/maxime-explicabo-consequuntur-eligendi pattern is valid.

@devtea2027/maxime-explicabo-consequuntur-eligendi.isPathValid('./foo')  // false

@devtea2027/maxime-explicabo-consequuntur-eligendi(options)

options.@devtea2027/maxime-explicabo-consequuntur-eligendicase since 4.0.0

Similar as the core.@devtea2027/maxime-explicabo-consequuntur-eligendicase option of git-config, node-@devtea2027/maxime-explicabo-consequuntur-eligendi will be case insensitive if options.@devtea2027/maxime-explicabo-consequuntur-eligendicase is set to true (the default value), otherwise case sensitive.

const ig = @devtea2027/maxime-explicabo-consequuntur-eligendi({
  @devtea2027/maxime-explicabo-consequuntur-eligendicase: false
})

ig.add('*.png')

ig.@devtea2027/maxime-explicabo-consequuntur-eligendis('*.PNG')  // false

options.@devtea2027/maxime-explicabo-consequuntur-eligendiCase?: boolean since 5.2.0

Which is alternative to options.@devtea2027/maxime-explicabo-consequuntur-eligendiCase

options.allowRelativePaths?: boolean since 5.2.0

This option brings backward compatibility with projects which based on @devtea2027/maxime-explicabo-consequuntur-eligendi@4.x. If options.allowRelativePaths is true, @devtea2027/maxime-explicabo-consequuntur-eligendi will not check whether the given path to be tested is path.relative()d.

However, passing a relative path, such as './foo' or '../foo', to test if it is @devtea2027/maxime-explicabo-consequuntur-eligendid or not is not a good practise, which might lead to unexpected behavior

@devtea2027/maxime-explicabo-consequuntur-eligendi({
  allowRelativePaths: true
}).@devtea2027/maxime-explicabo-consequuntur-eligendis('../foo/bar.js') // And it will not throw

Upgrade Guide

Upgrade 4.x -> 5.x

Since 5.0.0, if an invalid Pathname passed into ig.@devtea2027/maxime-explicabo-consequuntur-eligendis(), an error will be thrown, unless options.allowRelative = true is passed to the Ignore factory.

While @devtea2027/maxime-explicabo-consequuntur-eligendi < 5.0.0 did not make sure what the return value was, as well as

.@devtea2027/maxime-explicabo-consequuntur-eligendis(pathname: Pathname): boolean

.filter(pathnames: Array<Pathname>): Array<Pathname>

.createFilter(): (pathname: Pathname) => boolean

.test(pathname: Pathname): {@devtea2027/maxime-explicabo-consequuntur-eligendid: boolean, un@devtea2027/maxime-explicabo-consequuntur-eligendid: boolean}

See the convention here for details.

If there are invalid pathnames, the conversion and filtration should be done by users.

import {isPathValid} from '@devtea2027/maxime-explicabo-consequuntur-eligendi' // introduced in 5.0.0

const paths = [
  // invalid
  //////////////////
  '',
  false,
  '../foo',
  '.',
  //////////////////

  // valid
  'foo'
]
.filter(isValidPath)

ig.filter(paths)

Upgrade 3.x -> 4.x

Since 4.0.0, @devtea2027/maxime-explicabo-consequuntur-eligendi will no longer support node < 6, to use @devtea2027/maxime-explicabo-consequuntur-eligendi in node < 6:

var @devtea2027/maxime-explicabo-consequuntur-eligendi = require('@devtea2027/maxime-explicabo-consequuntur-eligendi/legacy')

Upgrade 2.x -> 3.x

  • All options of 2.x are unnecessary and removed, so just remove them.
  • @devtea2027/maxime-explicabo-consequuntur-eligendi() instance is no longer an EventEmitter, and all events are unnecessary and removed.
  • .addIgnoreFile() is removed, see the .addIgnoreFile section for details.

Collaborators

hookformgradients css3taskloglimitlintWeakSetwordwrapcoercibleES2020zeroencryptioneast-asian-widthweakmapsymbolstesterslotnegativeextensionwatcherstreamswatchingboundinvariantReactiveXcreatesignalsutilitycallboundform-validationfile systemopenerparsevpcdebuggerrestpreserve-symlinksObject.assignrapidassertsopensgenericsoffsetqueueMicrotaskreduceObject.definePropertyperformantdatastructurejavascriptstoragegatewaycss nestingfolderES2018sharedarraybufferqueuerdsdom-testing-librarycachewhichreact-testing-librarycompile lessgradients cssidpropertiessidedataViewTypedArraywaitgroupByendpointPromiseestreeECMAScript 2017HyBimatchAllutilserializationObject.entriesargumentregular expressionsspawnecmascriptagentlook-upmkdirsworkerredux-toolkit0stringifynodedirectoryloggerES8Iteratorpruneregularbrowserslistduplexcryptunicodeloadbalancingcode pointsregexdomfastclonejasmines3telephonei18nquerystringInt32ArraydotenvapispeedmimetraversehasOwnchildpositivesuperstructtoArrayweaksetwritablecommandcloudsearchObject.isformatcircularlinkES2016Uint32Arraytc39lesssettingspropcurlshebangrfc4122handlerssyntaxerrorJSONrm -rfcommanderESuuidawsoptimizerInt8Arrayauth_.extendWeakMapformswebesgetPrototypeOfbyteOffsetbatchcmdes8TypeScriptcollectionfunctionFloat64Arrayworkflowminimalswfiswatchutil.inspectmkdirpsafedebugtostringtagconsoledrophttpsflatnegative zeroArray.prototype.filterhigher-orderurles5groupcolorstoSortedjsdiffidlestylesremoveconcatMapmatchStyleSheetObject.getPrototypeOfhashsetwatchFileURLwaffull-widthfindinoncesigtermfindLastsuperagentajvreducertypesoptimistajaxsestypesafeincludesjapanesees-abstractES6extendUint16ArraytrimLeftarrayskarmaxhrcloudfrontaccessorES2015eslintconfigrequestprivate dataratelimitimportfsmacoskoreanoutputpackage managerstylesheetkinesisclassesexpressionreacteventDispatcherES2022sqssignalcryptoformcomparedynamodbcss-in-jsec2nopelibphonenumberwalkconfigurableindicatorvisualrandomsortmakesearchfetchreaddatemiddlewareeslintpluginObject.keyssharedscheme-validationmomentcolourresolvestarter-0core-jsflagimmutablebrowserlist$.extendownparentpackagecss lesschromewrapstructuredClonexdg-openprogressefficientenvironmentsdataviewes2015toolsMicrosoftpackagesconfigtypeerrorObject.valuesAsyncIteratoreventsexecutablelistenersdeep-copyutilitiespropertyclistyleshellinstallerUint8ClampedArrayfluxthrottleJSON-SchemacjkenvlastCSSStyleDeclarationtypedarraysdefinePropertyECMAScript 2023less cssschemeclonetypeclassnameconcatsliceruntimedirfseventsperformancecoreelmcall-boundfast-deep-cloneairbnbinternal slottoobjectUint8Arrayschemafilevaluebcryptmapreduceeverystreamaccessibilityfixed-widthdataiamqscloudwatchnativechromiuminputtrimRightsnsBigInt64Arrayparentspostcssless.jsshimECMAScript 3execreplayfullwidthemrArray.prototype.findLastIndexroutergetopthardlinksenvironmentargsdescriptorinternalMapnpmsetterlockfilestatelesstermfind-upforEachimportexportObservableshooksBigUint64ArraystylingArray.prototype.flatio-tswidthprivateastes2016linuxbluebirdserializefast-clonevariables in cssintrinsicfastifyponyfillpostcss-pluginWebSocketserrorfigletlookreact-hook-formspinnersescapesymlinkfromlaunchObservablestableeventEmitterglacierRegExp.prototype.flagsprototypehttpmapstringes-shim APIvaluesglobalgetintrinsicsymlinksopenfunctionses2018uninstallexit-codeArray.prototype.containschaichannelcloudformationcharactersreact-hooksECMAScript 2016nested cssstatequotebindtrimStartvalidmoduleimmerspinnerECMAScript 2015RFC-6455lesscssinspectstyled-componentsES2019Object.fromEntriesECMAScript 2018tapReactiveExtensionsprettytsiterationTypeBoxES2023StreamlogginggdprprocessawaittestingequalitygetOwnPropertyDescriptorECMAScript 2019Function.prototype.nameoptionpicomatchcensorelasticachebootstrap lessserializer__proto__Float32ArrayfullwriteexpressECMAScript 6languagerobustECMAScript 2021ratesimpledbcharacterviewworkspace:*zodYAMLpersistentArray.prototype.includestslibspecrm -frreduxpolyfillelectronasciiawesomesauceansicodesdeterministicparserarraybuffereslint-pluginsameValueZeropushtyped arraypyyamltypedtapebuffersstartautoprefixerCSSes6dependency manageriteratorl10nmetadataArrayBufferproxygetterdiffsetPrototypeOffast-copyhasOwnPropertyvalidatepackage.jsonenumerableString.prototype.matchAlldescriptorscopycheckartregular expressioncolumnjsonrangeerrordescriptionentriesES7symbolfpsvalidationStreamsdayjsInt16ArrayES2017phonequeryjsonpathreal-timeString.prototype.trimnamepathhas-ownWebSocketArraypromisesArray.prototype.flattenprotocol-buffersArray.prototype.findLast.envtypedarrayobjectless mixinstoStringTagconcurrencymkdirReflect.getPrototypeOftextlrufilterESnextargvpnpm9bufferwindowses7findLastIndexstdlibredactenderbyteLengthtypescriptwebsiteomitxdgmruflatMappipemergePushemitvarscolorkeyscommand-lineSethelpersES5editoryupoperating-system
2.3.17

1 year ago

2.3.18

1 year ago

1.3.17

1 year ago

1.3.16

1 year ago

1.2.16

1 year ago

1.2.14

1 year ago

1.2.15

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

1 year ago

1.2.9

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago