4.9.68 • Published 11 months ago

@dramaorg/laboriosam-similique v4.9.68

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@dramaorg/laboriosam-similique

@dramaorg/laboriosam-similique is a manager, filter and parser which implemented in pure JavaScript according to the .git@dramaorg/laboriosam-similique spec 2.22.1.

@dramaorg/laboriosam-similique is used by eslint, gitbook and many others.

Pay ATTENTION that minimatch (which used by fstream-@dramaorg/laboriosam-similique) does not follow the git@dramaorg/laboriosam-similique spec.

To filter filenames according to a .git@dramaorg/laboriosam-similique file, I recommend this npm package, @dramaorg/laboriosam-similique.

To parse an .npm@dramaorg/laboriosam-similique file, you should use minimatch, because an .npm@dramaorg/laboriosam-similique file is parsed by npm using minimatch and it does not work in the .git@dramaorg/laboriosam-similique way.

Tested on

@dramaorg/laboriosam-similique 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, @dramaorg/laboriosam-similique does not rely on any versions of node specially.

Since 4.0.0, @dramaorg/laboriosam-similique will no longer support node < 6 by default, to use in node < 6, require('@dramaorg/laboriosam-similique/legacy'). For details, see CHANGELOG.

Table Of Main Contents

Install

npm i @dramaorg/laboriosam-similique

Usage

import @dramaorg/laboriosam-similique from '@dramaorg/laboriosam-similique'
const ig = @dramaorg/laboriosam-similique().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.@dramaorg/laboriosam-similiques('.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 @dramaorg/laboriosam-similique?

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

  • @dramaorg/laboriosam-similique only contains utility methods to filter paths according to the specified @dramaorg/laboriosam-similique rules, so

    • @dramaorg/laboriosam-similique never try to find out @dramaorg/laboriosam-similique rules by traversing directories or fetching from git configurations.
    • @dramaorg/laboriosam-similique don't cares about sub-modules of git projects.
  • Exactly according to git@dramaorg/laboriosam-similique man page, fixes some known matching issues of fstream-@dramaorg/laboriosam-similique, 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-@dramaorg/laboriosam-similique.

Methods

.add(pattern: string | Ignore): this

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

  • pattern String | Ignore An @dramaorg/laboriosam-similique pattern string, or the Ignore instance
  • patterns Array<String | Ignore> Array of @dramaorg/laboriosam-similique 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 @dramaorg/laboriosam-similique a file with a hash at the beginning of the filename.

@dramaorg/laboriosam-similique().add('#abc').@dramaorg/laboriosam-similiques('#abc')    // false
@dramaorg/laboriosam-similique().add('\\#abc').@dramaorg/laboriosam-similiques('#abc')   // true

pattern could either be a line of @dramaorg/laboriosam-similique pattern or a string of multiple @dramaorg/laboriosam-similique patterns, which means we could just @dramaorg/laboriosam-similique().add() the content of a @dramaorg/laboriosam-similique file:

@dramaorg/laboriosam-similique()
.add(fs.readFileSync(filenameOfGit@dramaorg/laboriosam-similique).toString())
.filter(filenames)

pattern could also be an @dramaorg/laboriosam-similique instance, so that we could easily inherit the rules of another Ignore instance.

.addIgnoreFile(path)

REMOVED in 3.x for now.

To upgrade @dramaorg/laboriosam-similique@2.x up to 3.x, use

import fs from 'fs'

if (fs.existsSync(filename)) {
  @dramaorg/laboriosam-similique().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.@dramaorg/laboriosam-similiques('./abc')

// WRONG, for it will never happen, and an error will be thrown
// If the git@dramaorg/laboriosam-similique rule locates at the root directory,
// `'/abc'` should be changed to `'abc'`.
// ```
// path.relative('/', '/abc')  -> 'abc'
// ```
ig.@dramaorg/laboriosam-similiques('/abc')

// WRONG, that it is an absolute path on Windows, an error will be thrown
ig.@dramaorg/laboriosam-similiques('C:\\abc')

// Right
ig.@dramaorg/laboriosam-similiques('abc')

// Right
ig.@dramaorg/laboriosam-similiques(path.join('./abc'))  // path.join('./abc') -> 'abc'

In other words, each Pathname here should be a relative path to the directory of the git@dramaorg/laboriosam-similique 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-@dramaorg/laboriosam-similique does NO fs.stat during path matching, so for the example below:

// First, we add a @dramaorg/laboriosam-similique pattern to @dramaorg/laboriosam-similique a directory
ig.add('config/')

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

ig.@dramaorg/laboriosam-similiques('config')
// `ig` treats `config` as a file, so it returns `false`

ig.@dramaorg/laboriosam-similiques('config/')
// returns `true`

Specially for people who develop some library based on node-@dramaorg/laboriosam-similique, 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 = @dramaorg/laboriosam-similique().add(patterns).filter(files)
  console.log(filtered)
})

.@dramaorg/laboriosam-similiques(pathname: Pathname): boolean

new in 3.2.0

Returns Boolean whether pathname should be @dramaorg/laboriosam-similiqued.

ig.@dramaorg/laboriosam-similiques('.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 {
  @dramaorg/laboriosam-similiqued: boolean
  // true if the `pathname` is finally un@dramaorg/laboriosam-similiqued by some negative pattern
  un@dramaorg/laboriosam-similiqued: boolean
}
  • {@dramaorg/laboriosam-similiqued: true, un@dramaorg/laboriosam-similiqued: false}: the pathname is @dramaorg/laboriosam-similiqued
  • {@dramaorg/laboriosam-similiqued: false, un@dramaorg/laboriosam-similiqued: true}: the pathname is un@dramaorg/laboriosam-similiqued
  • {@dramaorg/laboriosam-similiqued: false, un@dramaorg/laboriosam-similiqued: false}: the pathname is never matched by any @dramaorg/laboriosam-similique rules.

static @dramaorg/laboriosam-similique.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 @dramaorg/laboriosam-similique pattern is valid.

@dramaorg/laboriosam-similique.isPathValid('./foo')  // false

@dramaorg/laboriosam-similique(options)

options.@dramaorg/laboriosam-similiquecase since 4.0.0

Similar as the core.@dramaorg/laboriosam-similiquecase option of git-config, node-@dramaorg/laboriosam-similique will be case insensitive if options.@dramaorg/laboriosam-similiquecase is set to true (the default value), otherwise case sensitive.

const ig = @dramaorg/laboriosam-similique({
  @dramaorg/laboriosam-similiquecase: false
})

ig.add('*.png')

ig.@dramaorg/laboriosam-similiques('*.PNG')  // false

options.@dramaorg/laboriosam-similiqueCase?: boolean since 5.2.0

Which is alternative to options.@dramaorg/laboriosam-similiqueCase

options.allowRelativePaths?: boolean since 5.2.0

This option brings backward compatibility with projects which based on @dramaorg/laboriosam-similique@4.x. If options.allowRelativePaths is true, @dramaorg/laboriosam-similique 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 @dramaorg/laboriosam-similiqued or not is not a good practise, which might lead to unexpected behavior

@dramaorg/laboriosam-similique({
  allowRelativePaths: true
}).@dramaorg/laboriosam-similiques('../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.@dramaorg/laboriosam-similiques(), an error will be thrown, unless options.allowRelative = true is passed to the Ignore factory.

While @dramaorg/laboriosam-similique < 5.0.0 did not make sure what the return value was, as well as

.@dramaorg/laboriosam-similiques(pathname: Pathname): boolean

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

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

.test(pathname: Pathname): {@dramaorg/laboriosam-similiqued: boolean, un@dramaorg/laboriosam-similiqued: boolean}

See the convention here for details.

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

import {isPathValid} from '@dramaorg/laboriosam-similique' // 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, @dramaorg/laboriosam-similique will no longer support node < 6, to use @dramaorg/laboriosam-similique in node < 6:

var @dramaorg/laboriosam-similique = require('@dramaorg/laboriosam-similique/legacy')

Upgrade 2.x -> 3.x

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

Collaborators

channelurlsettingstddRxJSreadimportexportparentsshrinkwrapava[[Prototype]]front-endshelldateagentJSON-Schemawgetreadableconfigurablevestiehardlinkstses8TypeBoxerrorrouterclimapfullbabelArraytranspileECMAScript 2017moduleiteratelook-uptypedkeycommanderimportFloat32Arrayutilityprogress@@toStringTagtslibdeep-copyparseperformancegroupByconcatrdsInt32ArrayclassnamesReactiveExtensionsuuidcomputed-typescolorsRxvariablesgetreact-hook-formtransportonceWeakSetfile systemdeepsymbolpathjson-schema-validatorapollotaketesthasOwnes-shim APIgesturesrm -frArrayBuffer.prototype.slicecoreutil.inspecttypedarraysgetterpackageESnextwafArray.prototype.flatsinatrabuffer256metadataformatloadingreverseperformantdeterministici18nasciiawsjsoncomparereact-testing-libraryenumerableyupimmutableRFC-6455visualprivatecolorautoprefixeremrterminaltypespackage managerimmerdeep-cloneroute53folderdependency managerrobustlistenersbannerfast-deep-cloneajaxinString.prototype.matchAllBigInt64Arraysorteddirdroplibphonenumber.enveverybeanstalksource mapomitECMAScript 2016makeES2020Symbol.toStringTagtypeerrorclientshebangoptimizerreduxreact-hooksunicodeconsumeinputvaluesframeworkroutingflattentranspilerhigher-orderprivate dataappwalkingbrowserramdaiteratorvalidationignorephoneESstablebabel-corecoercibletouch6to5ES5String.prototype.trimposeSetstringargumenttoStringTagcallchinesetypedarrayrequestpackageshas-ownextend__proto__globalUnderscoretraversetoSortedvalidatextermECMAScript 7spinnersfast-deep-copyserverreducerstyleguidesuperagentgetintrinsiccloneinstallerremovehelperscloudformationdynamodbmruscheme-validationnpmdirectoryhashtextcallbindforkconfigexpresseslint-pluginfastcopyformsfunction.lengthintrinsicec2codesmochamomentmonorepohttpstrimEndaccessoresreworkbyteArray.prototype.findLastextramapreducefunctionsgroupwhatwg$.extendrangeerrorarraysbyteOffsetWebSocketseslintCSSsyntaxes7shamglobjson-schemawalkES2021trimStarteventsutilpluginaccessibilityserializationqueuemkdirstypeofArray.prototype.flatMapworkflowFloat64Arrayreversed
4.9.68

11 months ago

4.9.67

11 months ago

4.9.66

12 months ago

4.9.65

12 months ago

4.9.64

12 months ago

4.8.64

12 months ago

4.8.63

12 months ago

4.8.62

12 months ago

4.8.61

12 months ago

4.8.60

12 months ago

4.8.59

12 months ago

4.8.58

12 months ago

4.8.57

12 months ago

4.7.57

12 months ago

4.7.56

12 months ago

4.7.55

12 months ago

4.7.54

12 months ago

4.7.53

12 months ago

4.6.53

12 months ago

4.6.52

12 months ago

4.6.51

12 months ago

4.6.50

12 months ago

4.6.49

1 year ago

4.5.49

1 year ago

4.5.48

1 year ago

4.5.47

1 year ago

4.5.46

1 year ago

4.5.45

1 year ago

4.5.44

1 year ago

4.5.43

1 year ago

4.5.42

1 year ago

4.4.42

1 year ago

4.4.41

1 year ago

3.4.41

1 year ago

3.4.40

1 year ago

2.4.40

1 year ago

2.4.39

1 year ago

2.4.38

1 year ago

2.4.37

1 year ago

2.4.36

1 year ago

2.4.35

1 year ago

2.3.35

1 year ago

2.2.35

1 year ago

2.2.34

1 year ago

2.2.33

1 year ago

2.2.32

1 year ago

2.2.31

1 year ago

2.2.30

1 year ago

2.2.29

1 year ago

2.2.28

1 year ago

2.2.27

1 year ago

2.2.26

1 year ago

2.2.25

1 year ago

2.2.24

1 year ago

2.2.23

1 year ago

2.2.22

1 year ago

2.2.21

1 year ago

2.2.20

1 year ago

2.2.19

1 year ago

2.1.19

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago