Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cspell-glob

Package Overview
Dependencies
Maintainers
1
Versions
272
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cspell-glob - npm Package Compare versions

Comparing version 0.1.14 to 0.1.17

CHANGELOG.md

9

lib/GlobMatcher.d.ts

@@ -0,1 +1,4 @@

/// <reference types="node" />
import * as path from 'path';
export declare type PathInterface = typeof path.posix;
export declare type GlobMatch = GlobMatchRule | GlobMatchNoRule;

@@ -19,2 +22,3 @@ export interface GlobMatchRule {

readonly matchEx: (filename: string) => GlobMatch;
readonly path: PathInterface;
/**

@@ -25,5 +29,8 @@ * Construct a `.gitignore` emulator

*/
constructor(patterns: string | string[], root?: string | undefined);
constructor(patterns: string | string[], root?: string | undefined, nodePath?: PathInterface);
/**
* Check to see if a filename matches any of the globs.
* If filename is relative, it is considered relative to the root.
* If filename is absolute and contained within the root, it will be made relative before being tested for a glob match.
* If filename is absolute and not contained within the root, it will be tested as is.
* @param filename full path of the file to check.

@@ -30,0 +37,0 @@ */

33

lib/GlobMatcher.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mm = require("micromatch");
const path = require("path");
class GlobMatcher {

@@ -10,9 +11,13 @@ /**

*/
constructor(patterns, root) {
constructor(patterns, root, nodePath) {
this.patterns = patterns;
this.root = root;
this.matchEx = buildMatcherFn(patterns, root);
this.path = (nodePath !== null && nodePath !== void 0 ? nodePath : path);
this.matchEx = buildMatcherFn(this.path, patterns, root);
}
/**
* Check to see if a filename matches any of the globs.
* If filename is relative, it is considered relative to the root.
* If filename is absolute and contained within the root, it will be made relative before being tested for a glob match.
* If filename is absolute and not contained within the root, it will be tested as is.
* @param filename full path of the file to check.

@@ -27,11 +32,18 @@ */

* This function attempts to emulate .gitignore functionality as much as possible.
*
* The resulting matcher function: (filename: string) => GlobMatch
*
* If filename is relative, it is considered relative to the root.
* If filename is absolute and contained within the root, it will be made relative before being tested for a glob match.
* If filename is absolute and not contained within the root, it will be tested as is.
*
* @param patterns the contents of a .gitignore style file or an array of individual glob rules.
* @param root the working directory
* @returns a function given a filename returns if it matches.
* @returns a function given a filename returns true if it matches.
*/
function buildMatcherFn(patterns, root) {
function buildMatcherFn(path, patterns, root) {
if (typeof patterns == 'string') {
patterns = patterns.split(/\r?\n/g);
}
const r = (root || '').replace(/\/$/, '');
const dirRoot = path.normalize(root || '/');
const rules = patterns

@@ -55,5 +67,8 @@ .map(p => p.trim())

const fn = (filename) => {
filename = filename.replace(/^[^/]/, '/$&');
const offset = r === filename.slice(0, r.length) ? r.length : 0;
const fname = filename.slice(offset);
filename = path.normalize(filename);
const offset = dirRoot === filename.slice(0, dirRoot.length) ? dirRoot.length : 0;
const lName = filename.slice(offset);
const filePath = path.parse(lName);
const relPath = path.join(filePath.dir.slice(filePath.root.length), filePath.base);
const fname = relPath.split(path.sep).join('/');
for (const rule of negRules) {

@@ -76,5 +91,5 @@ if (rule.fn(fname)) {

[/^[^/#][^/]*$/, '**/{$&,$&/**}',],
[/^\/(?!\/)/, ''],
[/\/$/, '$&**',],
[/^(([^/*])|([*][^*])).*[/]/, '/$&',],
];
//# sourceMappingURL=GlobMatcher.js.map
{
"name": "cspell-glob",
"version": "0.1.14",
"version": "0.1.17",
"description": "Glob matcher for cspell",

@@ -63,3 +63,3 @@ "keywords": [

},
"gitHead": "cbe103ba540d0ec7af38876372722802f80f4098"
"gitHead": "670c3f99fbbf021d1c2156f733c5ee01c9cb2f95"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc