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

tinyglobby

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinyglobby - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

9

dist/index.d.ts

@@ -6,8 +6,13 @@ interface GlobOptions {

ignore?: string[];
dot?: boolean;
deep?: number;
expandDirectories?: boolean;
onlyDirectories?: boolean;
onlyFiles?: boolean;
}
declare function glob(options?: GlobOptions | undefined): Promise<string[]>;
declare function globSync(options?: GlobOptions | undefined): string[];
declare function glob(patterns: string[], options?: Omit<GlobOptions, 'patterns'>): Promise<string[]>;
declare function glob(options: GlobOptions): Promise<string[]>;
declare function globSync(patterns: string[], options?: Omit<GlobOptions, 'patterns'>): string[];
declare function globSync(options: GlobOptions): string[];
export { type GlobOptions, glob, globSync };

@@ -37,2 +37,3 @@ "use strict";

module.exports = __toCommonJS(src_exports);
var import_node_path = __toESM(require("path"));
var import_fdir = require("fdir");

@@ -50,7 +51,7 @@ var import_picomatch = __toESM(require("picomatch"));

function processPatterns({ patterns, ignore = [], expandDirectories = true }) {
if (!patterns) {
return null;
}
const matchPatterns = [];
const ignorePatterns = ignore.map((p) => !p.endsWith("*") && expandDirectories ? expandDir(p) : p);
if (!patterns || patterns.length === 0) {
return { match: ["**/*"], ignore: ignorePatterns };
}
for (let pattern of patterns) {

@@ -68,31 +69,44 @@ if (!pattern.endsWith("*") && expandDirectories) {

}
function getFdirBuilder(options) {
function getFdirBuilder(options, cwd) {
const processed = processPatterns(options);
const fdirOptions = processed ? {
filters: [
(0, import_picomatch.default)(processed.match, {
dot: true,
ignore: processed.ignore,
windows: process.platform === "win32"
})
]
} : void 0;
let builder = new import_fdir.fdir(fdirOptions);
const matcher = (0, import_picomatch.default)(processed.match, {
dot: options.dot,
ignore: processed.ignore
});
const fdirOptions = {
// use relative paths in the matcher
filters: [options.absolute ? (p) => matcher(p.slice(cwd.length + 1)) : matcher],
relativePaths: true
};
if (options.deep) {
fdirOptions.maxDepth = options.deep;
}
if (options.absolute) {
builder = builder.withFullPaths();
} else {
builder = builder.withRelativePaths();
fdirOptions.relativePaths = false;
fdirOptions.resolvePaths = true;
fdirOptions.includeBasePath = true;
}
if (options.onlyDirectories) {
builder = builder.onlyDirs();
fdirOptions.excludeFiles = true;
fdirOptions.includeDirs = true;
} else if (options.onlyFiles === false) {
fdirOptions.includeDirs = true;
}
return builder;
return new import_fdir.fdir(fdirOptions);
}
async function glob(options = {}) {
var _a;
return getFdirBuilder(options).crawl((_a = options.cwd) != null ? _a : process.cwd()).withPromise();
async function glob(patternsOrOptions, options) {
if (patternsOrOptions && (options == null ? void 0 : options.patterns)) {
throw new Error("Cannot pass patterns as both an argument and an option");
}
const opts = Array.isArray(patternsOrOptions) ? { ...options, patterns: patternsOrOptions } : patternsOrOptions;
const cwd = opts.cwd ? import_node_path.default.resolve(opts.cwd) : process.cwd();
return getFdirBuilder(opts, cwd).crawl(cwd).withPromise();
}
function globSync(options = {}) {
var _a;
return getFdirBuilder(options).crawl((_a = options.cwd) != null ? _a : process.cwd()).sync();
function globSync(patternsOrOptions, options) {
if (patternsOrOptions && (options == null ? void 0 : options.patterns)) {
throw new Error("Cannot pass patterns as both an argument and an option");
}
const opts = Array.isArray(patternsOrOptions) ? { ...options, patterns: patternsOrOptions } : patternsOrOptions;
const cwd = opts.cwd ? import_node_path.default.resolve(opts.cwd) : process.cwd();
return getFdirBuilder(opts, cwd).crawl(cwd).sync();
}

@@ -99,0 +113,0 @@ // Annotate the CommonJS export names for ESM import in node:

{
"name": "tinyglobby",
"version": "0.1.2",
"version": "0.2.0",
"description": "A fast and minimal alternative to globby and fast-glob",

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

@@ -15,11 +15,10 @@ # tinyglobby

```js
import { glob } from 'tinyglobby';
import { glob, globSync } from 'tinyglobby';
await glob({ patterns: ['src/*.ts', '!**/*.d.ts'] });
```
await glob(['files/*.ts', '!**/*.d.ts'], { cwd: 'src' });
globSync(['src/**/*.ts'], { ignore: ['**/*.d.ts'] });
```js
import { globSync } from 'tinyglobby';
globSync({ patterns: ['src/*.ts', '!**/*.d.ts'] });
// you can also specify patterns inside the options object (exclusive to tinyglobby)
await glob({ patterns: ['src/*.ts', '!**/*.d.ts'], dot: true });
globSync({ patterns: ['src/**/*.ts', '!**/*.d.ts'], deep: 3 });
```

@@ -29,7 +28,10 @@

- `patterns`: An array of glob patterns to search for. If not present returns every file in the cwd.
- `patterns`: An array of glob patterns to search for. Defaults to `['**/*']`.
- `ignore`: An array of glob patterns to ignore.
- `cwd`: The current working directory in which to search. Defaults to `process.cwd()`.
- `absolute`: Whether to return absolute paths. Defaults to `false`.
- `dot`: Whether to allow entries starting with a dot. Defaults to `false`.
- `deep`: Maximum depth of a directory. Defaults to `Infinity`.
- `expandDirectories`: Whether to expand directories. Disable to best match `fast-glob`. Defaults to `true`.
- `onlyDirectories`: Enable to only return directories. Defaults to `false`.
- `onlyDirectories`: Enable to only return directories. Disables `onlyFiles` if set. Defaults to `false`.
- `onlyFiles`: Enable to only return files. Defaults to `true`.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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