Socket
Socket
Sign inDemoInstall

it-glob

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-glob - npm Package Compare versions

Comparing version 2.0.7 to 3.0.0

dist/src/index.browser.d.ts

31

dist/src/index.d.ts

@@ -6,2 +6,4 @@ /**

*
* File separators on Windows will be yielded as `/` and not `\`.
*
* @example

@@ -12,10 +14,5 @@ *

*
* const options = {
* cwd // defaults to process.cwd
* absolute // return absolute paths, defaults to false
* nodir // only yield file paths, skip directories
* // All options are passed through to fast-glob
* const options = {}
*
* // all other options are passed to minimatch
* }
*
* for await (const path of glob('/path/to/file', '**\/*', options)) {

@@ -26,23 +23,9 @@ * console.info(path)

*
* See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options.
* See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options.
*/
import type { MinimatchOptions } from 'minimatch';
export interface GlobOptions extends MinimatchOptions {
/**
* The current working directory
*/
cwd?: string;
/**
* If true produces absolute paths (default: false)
*/
absolute?: boolean;
/**
* If true yields file paths and skip directories (default: false)
*/
nodir?: boolean;
}
import type { Options } from 'fast-glob';
/**
* Async iterable filename pattern matcher
*/
export default function glob(dir: string, pattern: string, options?: GlobOptions): AsyncGenerator<string, void, undefined>;
export default function glob(dir: string, pattern: string, options?: Options): AsyncGenerator<string, void, undefined>;
//# sourceMappingURL=index.d.ts.map

@@ -6,2 +6,4 @@ /**

*
* File separators on Windows will be yielded as `/` and not `\`.
*
* @example

@@ -12,10 +14,5 @@ *

*
* const options = {
* cwd // defaults to process.cwd
* absolute // return absolute paths, defaults to false
* nodir // only yield file paths, skip directories
* // All options are passed through to fast-glob
* const options = {}
*
* // all other options are passed to minimatch
* }
*
* for await (const path of glob('/path/to/file', '**\/*', options)) {

@@ -26,7 +23,7 @@ * console.info(path)

*
* See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options.
* See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options.
*/
import fs from 'fs/promises';
import path from 'path';
import { minimatch } from 'minimatch';
import fs from 'node:fs/promises';
import path from 'node:path';
import fastGlob from 'fast-glob';
/**

@@ -37,31 +34,10 @@ * Async iterable filename pattern matcher

const absoluteDir = path.resolve(dir);
const relativeDir = path.relative(options.cwd ?? process.cwd(), dir);
const stats = await fs.stat(absoluteDir);
if (stats.isDirectory()) {
for await (const entry of _glob(absoluteDir, '', pattern, options)) {
yield entry;
}
return;
for await (const entry of fastGlob.stream(pattern, {
...options,
cwd: stats.isDirectory() ? dir : process.cwd()
})) {
yield entry.toString();
}
if (minimatch(relativeDir, pattern, options)) {
yield options.absolute === true ? absoluteDir : relativeDir;
}
}
async function* _glob(base, dir, pattern, options) {
for await (const entry of await fs.opendir(path.join(base, dir))) {
const relativeEntryPath = path.join(dir, entry.name);
const absoluteEntryPath = path.join(base, dir, entry.name);
let match = minimatch(relativeEntryPath, pattern, options);
const isDirectory = entry.isDirectory();
if (isDirectory && options.nodir === true) {
match = false;
}
if (match) {
yield options.absolute === true ? absoluteEntryPath : relativeEntryPath;
}
if (isDirectory) {
yield* _glob(base, relativeEntryPath, pattern, options);
}
}
}
//# sourceMappingURL=index.js.map
{
"GlobOptions": "https://achingbrain.github.io/it/interfaces/it_glob.GlobOptions.html",
".:GlobOptions": "https://achingbrain.github.io/it/interfaces/it_glob.GlobOptions.html",
"default": "https://achingbrain.github.io/it/functions/it_glob.default.html",
".:default": "https://achingbrain.github.io/it/functions/it_glob.default.html"
}
{
"name": "it-glob",
"version": "2.0.7",
"version": "3.0.0",
"description": "Async iterable filename pattern matcher",

@@ -41,3 +41,3 @@ "author": "Alex Potsides <alex@achingbrain.net>",

"scripts": {
"build": "aegir build",
"build": "aegir build --bundle false",
"lint": "aegir lint",

@@ -49,3 +49,3 @@ "dep-check": "aegir dep-check",

"dependencies": {
"minimatch": "^9.0.4"
"fast-glob": "^3.3.2"
},

@@ -57,5 +57,4 @@ "devDependencies": {

"browser": {
"fs/promises": false,
"path": false
"./dist/src/index.js": "./dist/src/index.browser.js"
}
}

@@ -27,2 +27,4 @@ # it-glob

File separators on Windows will be yielded as `/` and not \`\`.
## Example

@@ -33,10 +35,5 @@

const options = {
cwd // defaults to process.cwd
absolute // return absolute paths, defaults to false
nodir // only yield file paths, skip directories
// All options are passed through to fast-glob
const options = {}
// all other options are passed to minimatch
}
for await (const path of glob('/path/to/file', '**/*', options)) {

@@ -47,3 +44,3 @@ console.info(path)

See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options.
See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options.

@@ -50,0 +47,0 @@ # Install

@@ -6,2 +6,4 @@ /**

*
* File separators on Windows will be yielded as `/` and not `\`.
*
* @example

@@ -12,10 +14,5 @@ *

*
* const options = {
* cwd // defaults to process.cwd
* absolute // return absolute paths, defaults to false
* nodir // only yield file paths, skip directories
* // All options are passed through to fast-glob
* const options = {}
*
* // all other options are passed to minimatch
* }
*
* for await (const path of glob('/path/to/file', '**\/*', options)) {

@@ -26,70 +23,23 @@ * console.info(path)

*
* See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options.
* See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options.
*/
import fs from 'fs/promises'
import path from 'path'
import { minimatch } from 'minimatch'
import type { MinimatchOptions } from 'minimatch'
import fs from 'node:fs/promises'
import path from 'node:path'
import fastGlob from 'fast-glob'
import type { Options } from 'fast-glob'
export interface GlobOptions extends MinimatchOptions {
/**
* The current working directory
*/
cwd?: string
/**
* If true produces absolute paths (default: false)
*/
absolute?: boolean
/**
* If true yields file paths and skip directories (default: false)
*/
nodir?: boolean
}
/**
* Async iterable filename pattern matcher
*/
export default async function * glob (dir: string, pattern: string, options: GlobOptions = {}): AsyncGenerator<string, void, undefined> {
export default async function * glob (dir: string, pattern: string, options: Options = {}): AsyncGenerator<string, void, undefined> {
const absoluteDir = path.resolve(dir)
const relativeDir = path.relative(options.cwd ?? process.cwd(), dir)
const stats = await fs.stat(absoluteDir)
if (stats.isDirectory()) {
for await (const entry of _glob(absoluteDir, '', pattern, options)) {
yield entry
}
return
for await (const entry of fastGlob.stream(pattern, {
...options,
cwd: stats.isDirectory() ? dir : process.cwd()
})) {
yield entry.toString()
}
if (minimatch(relativeDir, pattern, options)) {
yield options.absolute === true ? absoluteDir : relativeDir
}
}
async function * _glob (base: string, dir: string, pattern: string, options: GlobOptions): AsyncGenerator<string, void, undefined> {
for await (const entry of await fs.opendir(path.join(base, dir))) {
const relativeEntryPath = path.join(dir, entry.name)
const absoluteEntryPath = path.join(base, dir, entry.name)
let match = minimatch(relativeEntryPath, pattern, options)
const isDirectory = entry.isDirectory()
if (isDirectory && options.nodir === true) {
match = false
}
if (match) {
yield options.absolute === true ? absoluteEntryPath : relativeEntryPath
}
if (isDirectory) {
yield * _glob(base, relativeEntryPath, pattern, options)
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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