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 0.0.3 to 0.0.4

28

index.js

@@ -8,6 +8,9 @@ 'use strict'

module.exports = async function * glob (dir, pattern, options = {}) {
const stats = await fs.stat(dir)
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(dir, pattern, options)) {
for await (const entry of _glob(absoluteDir, '', pattern, options)) {
yield entry

@@ -19,19 +22,20 @@ }

if (minimatch(dir, pattern)) {
yield dir
if (minimatch(relativeDir, pattern)) {
yield options.absolute ? absoluteDir : relativeDir
}
}
async function * _glob (dir, pattern, options) {
for await (const entry of await fs.readdir(dir)) {
const entryPath = path.join(dir, entry)
const stats = await fs.stat(entryPath)
async function * _glob (base, dir, pattern, options) {
for await (const entry of await fs.readdir(path.join(base, dir))) {
const relativeEntryPath = path.join(dir, entry)
const absoluteEntryPath = path.join(base, dir, entry)
const stats = await fs.stat(absoluteEntryPath)
if (stats.isDirectory()) {
yield * _glob(entryPath, pattern, options)
yield * _glob(base, relativeEntryPath, pattern, options)
} else {
let match = minimatch(entryPath, pattern, options)
let match = minimatch(relativeEntryPath, pattern, options)
if (options.ignore && match && options.ignore.reduce((acc, curr) => {
return acc || minimatch(entryPath, curr, options)
return acc || minimatch(relativeEntryPath, curr, options)
}, false)) {

@@ -42,3 +46,3 @@ match = false

if (match) {
yield entryPath
yield options.absolute ? absoluteEntryPath : relativeEntryPath
}

@@ -45,0 +49,0 @@ }

{
"name": "it-glob",
"version": "0.0.3",
"version": "0.0.4",
"description": "Async iterable filename pattern matcher",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -21,3 +21,6 @@ # it-glob

'glob' // glob patterns to ignore
]
],
cwd // defaults to process.cwd
absolute // return absolute paths, defaults to false
// all other options are passed to minimatch

@@ -24,0 +27,0 @@ }

import test from 'ava'
import all from 'async-iterator-all'
import glob from '../'
import path from 'path'

@@ -31,3 +32,6 @@ test('it should match file', async t => {

const files = await all(glob('.', '**/*', {
ignore: ['*/index.js']
ignore: [
'*/index.js',
'**/node_modules/**'
]
}))

@@ -37,1 +41,39 @@

})
test('it should ignore files from absolute directory', async t => {
const dir = path.resolve(__dirname, '..')
const files = await all(glob(dir, '**/*', {
ignore: [
'test/index.js',
'**/node_modules/**'
]
}))
t.falsy(files.includes(path.resolve(__dirname, 'index.js')))
})
test('it returns absolute paths', async t => {
const dir = path.resolve(__dirname, '..')
const files = await all(glob(dir, '**/*', {
absolute: true
}))
files.forEach(file => {
t.truthy(file.startsWith('/'))
})
})
test('it returns relative paths', async t => {
const dir = path.resolve(__dirname, '..')
const files = await all(glob(dir, '**/*', {
absolute: false
}))
files.forEach(file => {
t.falsy(file.startsWith('/'))
})
})
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