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

@thi.ng/file-io

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/file-io - npm Package Compare versions

Comparing version 0.5.28 to 1.0.1

14

CHANGELOG.md
# Change Log
- **Last updated**: 2023-10-23T07:37:37Z
- **Last updated**: 2023-11-09T10:28:18Z
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)

@@ -12,2 +12,14 @@

# [1.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@1.0.0) (2023-11-09)
#### 🛑 Breaking changes
- update matching logic for files()/dirs() ([8f275b5](https://github.com/thi-ng/umbrella/commit/8f275b5))
- BREAKING CHANGE: files()/dirs() matchers use full relative sub-path
- add support for arbitrary predicate fns as matcher
#### ♻️ Refactoring
- update all tests (packages A-S) ([e3085e4](https://github.com/thi-ng/umbrella/commit/e3085e4))
## [0.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@0.5.0) (2023-02-05)

@@ -14,0 +26,0 @@

15

files.d.ts

@@ -0,9 +1,12 @@

import type { Predicate } from "@thi.ng/api";
import type { ILogger } from "@thi.ng/logger";
/**
* Recursively reads given directory (up to given max. depth, default: infinite)
* and yields sequence of file names matching given extension (or regexp).
* and yields sequence of file names matching given extension (or regexp or
* predicate).
*
* @remarks
* If NO `match` is given, all files will be matched. Directory names will not
* be tested and are always traversed (up to given `maxDepth`).
* Files will be matched using their _full_ relative sub-path (starting with
* given `dir`). If NO `match` is given, all files will be matched. Directories
* will *not* be tested and are always traversed (up to given `maxDepth`).
*

@@ -18,3 +21,3 @@ * The optional `logger` is only used to log errors for files which couldn't be

*/
export declare const files: (dir: string, match?: string | RegExp, maxDepth?: number, logger?: ILogger) => IterableIterator<string>;
export declare const files: (dir: string, match?: string | RegExp | Predicate<string>, maxDepth?: number, logger?: ILogger) => IterableIterator<string>;
/**

@@ -25,3 +28,3 @@ * Similar to {@link files}, however yields iterator of only matching

* @remarks
* Unlike the regex matching in {@link files}, here the regex will be applied to
* Like the matcher in {@link files}, the regex or predicate will be applied to
* the _full_ sub-path (starting with `dir`) in order to determine a match.

@@ -34,3 +37,3 @@ *

*/
export declare const dirs: (dir: string, match?: string | RegExp, maxDepth?: number, logger?: ILogger) => IterableIterator<string>;
export declare const dirs: (dir: string, match?: string | RegExp | Predicate<string>, maxDepth?: number, logger?: ILogger) => IterableIterator<string>;
//# sourceMappingURL=files.d.ts.map

@@ -0,1 +1,2 @@

import { isFunction } from "@thi.ng/checks/is-function";
import { isString } from "@thi.ng/checks/is-string";

@@ -7,7 +8,9 @@ import { readdirSync, statSync } from "fs";

* Recursively reads given directory (up to given max. depth, default: infinite)
* and yields sequence of file names matching given extension (or regexp).
* and yields sequence of file names matching given extension (or regexp or
* predicate).
*
* @remarks
* If NO `match` is given, all files will be matched. Directory names will not
* be tested and are always traversed (up to given `maxDepth`).
* Files will be matched using their _full_ relative sub-path (starting with
* given `dir`). If NO `match` is given, all files will be matched. Directories
* will *not* be tested and are always traversed (up to given `maxDepth`).
*

@@ -26,4 +29,4 @@ * The optional `logger` is only used to log errors for files which couldn't be

return;
const re = __ensureRegEx(match);
for (let f of readdirSync(dir)) {
const pred = __ensurePred(match);
for (let f of readdirSync(dir).sort()) {
const curr = dir + sep + f;

@@ -34,3 +37,3 @@ try {

}
else if (re.test(f)) {
else if (pred(curr)) {
yield curr;

@@ -50,3 +53,3 @@ }

* @remarks
* Unlike the regex matching in {@link files}, here the regex will be applied to
* Like the matcher in {@link files}, the regex or predicate will be applied to
* the _full_ sub-path (starting with `dir`) in order to determine a match.

@@ -63,8 +66,8 @@ *

return;
const re = __ensureRegEx(match);
for (let f of readdirSync(dir)) {
const pred = __ensurePred(match);
for (let f of readdirSync(dir).sort()) {
const curr = dir + sep + f;
try {
if (statSync(curr).isDirectory()) {
if (re.test(curr))
if (pred(curr))
yield curr;

@@ -82,1 +85,5 @@ yield* __dirs(curr, match, logger, maxDepth, depth + 1);

const __ensureRegEx = (match) => isString(match) ? new RegExp(`${match.replace(/\./g, "\\.")}$`) : match;
const __ensurePred = (match) => isFunction(match)
? match
: ((match = __ensureRegEx(match)),
(x) => match.test(x));
{
"name": "@thi.ng/file-io",
"version": "0.5.28",
"version": "1.0.1",
"description": "Assorted file I/O utils (with logging support) for NodeJS",

@@ -31,20 +31,19 @@ "type": "module",

"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
"doc:readme": "yarn doc:stats && tools:readme",
"doc:stats": "tools:module-stats",
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
"pub": "yarn npm publish --access public",
"test": "testament test"
"test": "bun test"
},
"dependencies": {
"@thi.ng/api": "^8.9.6",
"@thi.ng/checks": "^3.4.6",
"@thi.ng/hex": "^2.3.18",
"@thi.ng/logger": "^1.4.22",
"@thi.ng/random": "^3.6.12"
"@thi.ng/api": "^8.9.8",
"@thi.ng/checks": "^3.4.8",
"@thi.ng/hex": "^2.3.20",
"@thi.ng/logger": "^1.4.24",
"@thi.ng/random": "^3.6.14"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.38.0",
"@thi.ng/testament": "^0.3.24",
"@microsoft/api-extractor": "^7.38.2",
"@thi.ng/testament": "^0.4.1",
"rimraf": "^5.0.5",
"tools": "^0.0.1",
"typedoc": "^0.25.2",
"typedoc": "^0.25.3",
"typescript": "^5.2.2"

@@ -120,3 +119,3 @@ },

},
"gitHead": "336bd1bf95825b3c318a3ab49c54451c94aaa883\n"
"gitHead": "669a3151e4302480244fe3e60eff5e732ea5b7a7\n"
}

@@ -47,3 +47,3 @@ <!-- This file is generated - DO NOT EDIT! -->

Package sizes (brotli'd, pre-treeshake): ESM: 1.25 KB
Package sizes (brotli'd, pre-treeshake): ESM: 1.30 KB

@@ -50,0 +50,0 @@ ## Dependencies

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