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

tiny-fsearch

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-fsearch - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

dist/grep.js

17

dist/binding.js

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

const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const bindings_1 = __importDefault(require("bindings"));

@@ -19,20 +18,14 @@ const options_1 = require("./options");

throw new Error(`Query source "${source}" does not exist`);
const params = Object.assign({}, options_1.IQueryOptions.defaults, options);
const sources = options_1.IQueryOptions.Resolve.sources(path_1.default.resolve(source), params);
const predicate = options_1.IQueryOptions.Resolve.predicate(input, params);
const alternatives = options_1.IQueryOptions.Resolve.alternatives(sources, params);
return Binding.raw().synchronous(sources, predicate, alternatives);
const { sources, predicate, alternatives, maximum } = options_1.IQueryOptions.Resolve.all(source, input, options);
return Binding.raw().synchronous(sources, predicate, alternatives, maximum);
};
Binding.stream = (source, input, options) => {
if (input === '')
return { async *[Symbol.asyncIterator]() { } };
return { async *[Symbol.asyncIterator]() { }, sources: [] };
if (!fs_1.default.existsSync(source))
throw new Error(`Query source "${source}" does not exist`);
const params = Object.assign({}, options_1.IQueryOptions.defaults, options);
const sources = options_1.IQueryOptions.Resolve.sources(path_1.default.resolve(source), params);
const predicate = options_1.IQueryOptions.Resolve.predicate(input, params);
const alternatives = options_1.IQueryOptions.Resolve.alternatives(sources, params);
return new (Binding.raw().Generator)(sources, predicate, alternatives);
const { sources, predicate, alternatives, maximum } = options_1.IQueryOptions.Resolve.all(source, input, options);
return Object.assign(new (Binding.raw().Generator)(sources, predicate, alternatives, maximum), { sources });
};
Binding.raw = () => (0, bindings_1.default)('fsearch');
})(Binding = exports.Binding || (exports.Binding = {}));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fsearch = void 0;
const grep_1 = require("./grep");
const binding_1 = require("./binding");
var fsearch;
(function (fsearch) {
fsearch.sync = (source, predicate, options = {}) => binding_1.Binding.sync(source, predicate, options);
fsearch.stream = (source, predicate, options = {}) => binding_1.Binding.stream(source, predicate, options);
fsearch.sync = (source, predicate, options = {}) => binding_1.Binding.sync(source, predicate, options);
})(fsearch = exports.fsearch || (exports.fsearch = {}));
(function (fsearch) {
var grep;
(function (grep) {
grep.sync = (source, predicate, options = {}) => grep_1.Grep.sync(source, predicate, options);
grep.stream = (source, predicate, options = {}) => grep_1.Grep.stream(source, predicate, options);
})(grep = fsearch.grep || (fsearch.grep = {}));
})(fsearch = exports.fsearch || (exports.fsearch = {}));
exports.default = fsearch;

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

const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fast_glob_1 = __importDefault(require("fast-glob"));

@@ -13,5 +14,6 @@ var IQueryOptions;

IQueryOptions.defaults = {
exclude: [],
ignoreCase: true,
matchWholeWord: false,
maximum: Number.MAX_SAFE_INTEGER,
exclude: [],
alternatives: {},

@@ -23,3 +25,13 @@ };

(function (Resolve) {
Resolve.predicate = (predicate, { matchWholeWord }) => {
Resolve.all = (source, input, options) => {
const params = Object.assign({}, IQueryOptions.defaults, options);
const sources = m_sources(path_1.default.resolve(source), params);
return {
sources,
maximum: params.maximum,
predicate: m_predicate(input, params),
alternatives: m_alternatives(sources, params),
};
};
const m_predicate = (predicate, { matchWholeWord }) => {
if (typeof predicate === 'object')

@@ -33,3 +45,3 @@ predicate = predicate.source;

};
Resolve.sources = (source, { exclude }) => {
const m_sources = (source, { exclude }) => {
const options = {

@@ -45,3 +57,3 @@ dot: true,

};
Resolve.alternatives = (sources, { alternatives: _ }) => {
const m_alternatives = (sources, { alternatives: _ }) => {
for (const key in Object.keys(_))

@@ -48,0 +60,0 @@ !sources.includes(key) && delete _[key];

@@ -39,1 +39,8 @@ "use strict";

});
(0, ava_1.default)(`Query Async - restricted "${Constants.TEST_PREDICATE}"`, async (_) => {
const stream = __1.default.stream('lib', Constants.TEST_PREDICATE, { maximum: 0 });
let counter = 0;
for await (const matches of stream)
counter += matches.length;
_.is(counter, 0, 'Invalid result count');
});

@@ -12,7 +12,9 @@ "use strict";

const predicate = 'time';
const options = { exclude: ['**/node_modules'] };
const options = { exclude: [] };
const iters = 1;
const synchronous = await measure_1.Measure.record(iters, () => __1.default.sync(cwd, predicate, options));
const parallel = await measure_1.Measure.record(iters, async () => {
for await (const _ of __1.default.stream(cwd, predicate, options))
const stream = __1.default.stream(cwd, predicate, options);
_.log('Files to search:', stream.sources.length);
for await (const _ of stream)
void 0;

@@ -19,0 +21,0 @@ });

@@ -36,1 +36,5 @@ "use strict";

});
(0, ava_1.default)(`Query Sync - restrict "${Constants.TEST_PREDICATE}"`, (_) => {
const results = __1.default.sync('lib', Constants.TEST_PREDICATE, { maximum: 0 });
_.is(results.length, 0, 'Invalid result count');
});

@@ -9,11 +9,15 @@ /// <reference types="node" />

}
type Arguments = [sources: string[], predicate: string, alternatives: NodeJS.Dict<Buffer>, maximum: number];
interface IRaw {
synchronous: (sources: string[], predicate: string, alternatives: NodeJS.Dict<Buffer>) => IQueryMatch[];
synchronous: (...args: Arguments) => IQueryMatch[];
Generator: {
new (sources: string[], predicate: string, alternatives: NodeJS.Dict<Buffer>): IGenerator;
new (...args: Arguments): IGenerator;
};
}
interface IParallel extends IGenerator {
sources: string[];
}
const sync: (source: string, input: string | RegExp, options: Partial<IQueryOptions>) => IQueryMatch[];
const stream: (source: string, input: string | RegExp, options: Partial<IQueryOptions>) => IGenerator;
const stream: (source: string, input: string | RegExp, options: Partial<IQueryOptions>) => IParallel;
const raw: () => IRaw;
}

@@ -9,5 +9,9 @@ import { Binding } from './binding';

}
const stream: (source: string, predicate: string | RegExp, options?: Partial<IOptions>) => Binding.IGenerator;
const sync: (source: string, predicate: string | RegExp, options?: Partial<IOptions>) => IQueryMatch[];
const stream: (source: string, predicate: string | RegExp, options?: Partial<IOptions>) => Binding.IParallel;
}
export declare namespace fsearch.grep {
const sync: (source: string, predicate: string | RegExp, options?: Partial<IOptions>) => IQueryMatch[];
const stream: (source: string, predicate: string | RegExp, options?: Partial<IOptions>) => Binding.IGenerator;
}
export default fsearch;

@@ -7,2 +7,3 @@ /// <reference types="node" />

readonly matchWholeWord: boolean;
readonly maximum: number;
readonly alternatives: NodeJS.Dict<Buffer>;

@@ -14,5 +15,9 @@ }

export declare namespace IQueryOptions.Resolve {
const predicate: (predicate: string | RegExp, { matchWholeWord }: IQueryOptions) => string;
const sources: (source: string, { exclude }: IQueryOptions) => string[];
const alternatives: (sources: string[], { alternatives: _ }: IQueryOptions) => NodeJS.Dict<Buffer>;
interface IValue {
maximum: number;
sources: string[];
predicate: string;
alternatives: NodeJS.Dict<Buffer>;
}
const all: (source: string, input: string | RegExp, options: Partial<IQueryOptions>) => IValue;
}

@@ -5,3 +5,4 @@ export interface IQueryMatch {

readonly length: number;
readonly content: string;
readonly filePath: string;
}
{
"name": "tiny-fsearch",
"version": "2.0.2",
"version": "2.0.3",
"description": "A small and versatile find-in-file/search library.",

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

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