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

filelist-utils

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filelist-utils - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

lib-esm/Options.d.ts

5

lib-esm/fileCollectionFromFileList.d.ts

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -14,3 +13,3 @@ * Generate a FileCollection from a FileList

*/
export declare function fileCollectionFromFileList(fileList: FileList, options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromFileList(fileList: FileList, options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromFileList.d.ts.map
import { FileCollection } from './FileCollection';
import { maybeExpand } from './utilities/maybeExpand';
import { maybeFilter } from './utilities/maybeFilter';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -18,3 +17,3 @@ /**

for (const file of fileList) {
fileCollectionItems.push({
const item = {
name: file.name,

@@ -28,6 +27,5 @@ size: file.size,

stream: () => file.stream(),
});
};
fileCollectionItems.push(...(await expandAndFilter(item, options)));
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);

@@ -34,0 +32,0 @@ return new FileCollection(fileCollectionItems);

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -12,3 +11,3 @@ * Generate a FileCollection from an array of File

*/
export declare function fileCollectionFromFiles(files: File[], options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromFiles(files: File[], options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromFiles.d.ts.map
import { FileCollection } from './FileCollection';
import { maybeExpand } from './utilities/maybeExpand';
import { maybeFilter } from './utilities/maybeFilter';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -16,3 +15,3 @@ /**

for (const file of files) {
fileCollectionItems.push({
const item = {
name: file.name,

@@ -26,6 +25,5 @@ size: file.size,

stream: () => file.stream(),
});
};
fileCollectionItems.push(...(await expandAndFilter(item, options)));
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);

@@ -32,0 +30,0 @@ return new FileCollection(fileCollectionItems);

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -10,3 +9,3 @@ * Generate a FileCollection from a directory path

*/
export declare function fileCollectionFromPath(path: string, options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromPath(path: string, options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromPath.d.ts.map

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -10,3 +9,3 @@ * Generate a FileCollection from a directory path

*/
export declare function fileCollectionFromPaths(paths: string[], options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromPaths(paths: string[], options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromPaths.d.ts.map

19

lib-esm/fileCollectionFromPaths.js

@@ -6,4 +6,3 @@ import { createReadStream } from 'node:fs';

import { FileCollection } from './FileCollection';
import { maybeExpand } from './utilities/maybeExpand';
import { maybeFilter } from './utilities/maybeFilter';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -21,10 +20,8 @@ /**

const base = basename(path);
await appendFiles(fileCollectionItems, path, base);
await appendFiles(fileCollectionItems, path, base, options);
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);
return new FileCollection(fileCollectionItems);
}
async function appendFiles(fileCollection, currentDir, base) {
async function appendFiles(fileCollection, currentDir, base, options = {}) {
const entries = await readdir(currentDir);

@@ -35,9 +32,10 @@ for (let entry of entries) {

if (info.isDirectory()) {
await appendFiles(fileCollection, current, `${base}/${entry}`);
await appendFiles(fileCollection, current, `${base}/${entry}`, options);
}
else {
fileCollection.push({
const relativePath = `${base}/${entry}`;
const item = {
name: entry,
size: info.size,
relativePath: `${base}/${entry}`,
relativePath,
lastModified: Math.round(info.mtimeMs),

@@ -59,3 +57,4 @@ text: () => {

},
});
};
fileCollection.push(...(await expandAndFilter(item, options)));
}

@@ -62,0 +61,0 @@ }

import { CacheOptions } from './CachedFileCollectionItem';
import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { Options } from './Options';
import { WebSource } from './WebSourceFile';
import { FilterOptions } from './utilities/maybeFilter';
/**

@@ -18,3 +17,3 @@ * Creates a FileCollection from a webSource.

baseURL?: string | URL;
} & CacheOptions & ExpandOptions & FilterOptions): Promise<FileCollection>;
} & CacheOptions & Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromWebSource.d.ts.map
import fetch from 'cross-fetch';
import { CachedFileCollectionItem, } from './CachedFileCollectionItem';
import { FileCollection } from './FileCollection';
import { maybeExpand } from './utilities/maybeExpand';
import { maybeFilter } from './utilities/maybeFilter';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -48,3 +47,3 @@ /**

const fileURL = new URL(entry.relativePath, realBaseURL);
const filecollectionItem = {
const item = {
name: entry.relativePath.split('/').pop() || '',

@@ -66,8 +65,8 @@ size,

};
fileCollectionItems.push(cache
? new CachedFileCollectionItem(filecollectionItem)
: filecollectionItem);
const expanded = await expandAndFilter(item, options);
// we should be aware that we don't cache the zip file itself
for (const item of expanded) {
fileCollectionItems.push(cache ? new CachedFileCollectionItem(item) : item);
}
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);

@@ -74,0 +73,0 @@ return new FileCollection(fileCollectionItems);

import JSZip from 'jszip';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];

@@ -11,4 +11,4 @@ /**

*/
export declare function fileCollectionFromZip(zipContent: ZipFileContent, options?: FilterOptions): Promise<FileCollection>;
export declare function fileCollectionItemsFromZip(zipContent: ZipFileContent): Promise<FileCollectionItem[]>;
export declare function fileCollectionFromZip(zipContent: ZipFileContent, options?: Options): Promise<FileCollection>;
export declare function fileCollectionItemsFromZip(zipContent: ZipFileContent, options?: Options): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionFromZip.d.ts.map
import JSZip from 'jszip';
import { FileCollection } from './FileCollection';
import { maybeFilter } from './utilities/maybeFilter';
import { shouldAddItem } from './utilities/shouldAddItem';
/**

@@ -10,7 +10,6 @@ * Create a FileCollection from a zip

export async function fileCollectionFromZip(zipContent, options = {}) {
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent, options);
return new FileCollection(fileCollectionItems);
}
export async function fileCollectionItemsFromZip(zipContent) {
export async function fileCollectionItemsFromZip(zipContent, options = {}) {
const jsZip = new JSZip();

@@ -23,3 +22,5 @@ const zip = await jsZip.loadAsync(zipContent);

continue;
fileCollectionItems.push({
if (!shouldAddItem(entry.name, options.filter))
continue;
const item = {
name: entry.name.replace(/^.*\//, ''),

@@ -40,4 +41,2 @@ relativePath: entry.name,

void entry.async('arraybuffer').then((arrayBuffer) => {
//todo the test are currently passing I don't know how to solve this
//@ts-expect-error to fix
controller.enqueue(arrayBuffer);

@@ -49,3 +48,4 @@ controller.close();

},
});
};
fileCollectionItems.push(item);
}

@@ -52,0 +52,0 @@ return fileCollectionItems;

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -14,3 +13,3 @@ * Generate a FileCollection from a FileList

*/
export declare function fileCollectionFromFileList(fileList: FileList, options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromFileList(fileList: FileList, options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromFileList.d.ts.map

@@ -5,4 +5,3 @@ "use strict";

const FileCollection_1 = require("./FileCollection");
const maybeExpand_1 = require("./utilities/maybeExpand");
const maybeFilter_1 = require("./utilities/maybeFilter");
const expandAndFilter_1 = require("./utilities/expand/expandAndFilter");
const sortCollectionItems_1 = require("./utilities/sortCollectionItems");

@@ -22,3 +21,3 @@ /**

for (const file of fileList) {
fileCollectionItems.push({
const item = {
name: file.name,

@@ -32,6 +31,5 @@ size: file.size,

stream: () => file.stream(),
});
};
fileCollectionItems.push(...(await (0, expandAndFilter_1.expandAndFilter)(item, options)));
}
fileCollectionItems = await (0, maybeExpand_1.maybeExpand)(fileCollectionItems, options);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
(0, sortCollectionItems_1.sortCollectionItems)(fileCollectionItems);

@@ -38,0 +36,0 @@ return new FileCollection_1.FileCollection(fileCollectionItems);

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -12,3 +11,3 @@ * Generate a FileCollection from an array of File

*/
export declare function fileCollectionFromFiles(files: File[], options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromFiles(files: File[], options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromFiles.d.ts.map

@@ -5,4 +5,3 @@ "use strict";

const FileCollection_1 = require("./FileCollection");
const maybeExpand_1 = require("./utilities/maybeExpand");
const maybeFilter_1 = require("./utilities/maybeFilter");
const expandAndFilter_1 = require("./utilities/expand/expandAndFilter");
const sortCollectionItems_1 = require("./utilities/sortCollectionItems");

@@ -20,3 +19,3 @@ /**

for (const file of files) {
fileCollectionItems.push({
const item = {
name: file.name,

@@ -30,6 +29,5 @@ size: file.size,

stream: () => file.stream(),
});
};
fileCollectionItems.push(...(await (0, expandAndFilter_1.expandAndFilter)(item, options)));
}
fileCollectionItems = await (0, maybeExpand_1.maybeExpand)(fileCollectionItems, options);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
(0, sortCollectionItems_1.sortCollectionItems)(fileCollectionItems);

@@ -36,0 +34,0 @@ return new FileCollection_1.FileCollection(fileCollectionItems);

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -10,3 +9,3 @@ * Generate a FileCollection from a directory path

*/
export declare function fileCollectionFromPath(path: string, options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromPath(path: string, options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromPath.d.ts.map

@@ -1,4 +0,3 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
/**

@@ -10,3 +9,3 @@ * Generate a FileCollection from a directory path

*/
export declare function fileCollectionFromPaths(paths: string[], options?: ExpandOptions & FilterOptions): Promise<FileCollection>;
export declare function fileCollectionFromPaths(paths: string[], options?: Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromPaths.d.ts.map

@@ -9,4 +9,3 @@ "use strict";

const FileCollection_1 = require("./FileCollection");
const maybeExpand_1 = require("./utilities/maybeExpand");
const maybeFilter_1 = require("./utilities/maybeFilter");
const expandAndFilter_1 = require("./utilities/expand/expandAndFilter");
const sortCollectionItems_1 = require("./utilities/sortCollectionItems");

@@ -24,6 +23,4 @@ /**

const base = (0, node_path_1.basename)(path);
await appendFiles(fileCollectionItems, path, base);
await appendFiles(fileCollectionItems, path, base, options);
}
fileCollectionItems = await (0, maybeExpand_1.maybeExpand)(fileCollectionItems, options);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
(0, sortCollectionItems_1.sortCollectionItems)(fileCollectionItems);

@@ -33,3 +30,3 @@ return new FileCollection_1.FileCollection(fileCollectionItems);

exports.fileCollectionFromPaths = fileCollectionFromPaths;
async function appendFiles(fileCollection, currentDir, base) {
async function appendFiles(fileCollection, currentDir, base, options = {}) {
const entries = await (0, promises_1.readdir)(currentDir);

@@ -40,9 +37,10 @@ for (let entry of entries) {

if (info.isDirectory()) {
await appendFiles(fileCollection, current, `${base}/${entry}`);
await appendFiles(fileCollection, current, `${base}/${entry}`, options);
}
else {
fileCollection.push({
const relativePath = `${base}/${entry}`;
const item = {
name: entry,
size: info.size,
relativePath: `${base}/${entry}`,
relativePath,
lastModified: Math.round(info.mtimeMs),

@@ -64,3 +62,4 @@ text: () => {

},
});
};
fileCollection.push(...(await (0, expandAndFilter_1.expandAndFilter)(item, options)));
}

@@ -67,0 +66,0 @@ }

import { CacheOptions } from './CachedFileCollectionItem';
import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { Options } from './Options';
import { WebSource } from './WebSourceFile';
import { FilterOptions } from './utilities/maybeFilter';
/**

@@ -18,3 +17,3 @@ * Creates a FileCollection from a webSource.

baseURL?: string | URL;
} & CacheOptions & ExpandOptions & FilterOptions): Promise<FileCollection>;
} & CacheOptions & Options): Promise<FileCollection>;
//# sourceMappingURL=fileCollectionFromWebSource.d.ts.map

@@ -10,4 +10,3 @@ "use strict";

const FileCollection_1 = require("./FileCollection");
const maybeExpand_1 = require("./utilities/maybeExpand");
const maybeFilter_1 = require("./utilities/maybeFilter");
const expandAndFilter_1 = require("./utilities/expand/expandAndFilter");
const sortCollectionItems_1 = require("./utilities/sortCollectionItems");

@@ -55,3 +54,3 @@ /**

const fileURL = new URL(entry.relativePath, realBaseURL);
const filecollectionItem = {
const item = {
name: entry.relativePath.split('/').pop() || '',

@@ -73,8 +72,8 @@ size,

};
fileCollectionItems.push(cache
? new CachedFileCollectionItem_1.CachedFileCollectionItem(filecollectionItem)
: filecollectionItem);
const expanded = await (0, expandAndFilter_1.expandAndFilter)(item, options);
// we should be aware that we don't cache the zip file itself
for (const item of expanded) {
fileCollectionItems.push(cache ? new CachedFileCollectionItem_1.CachedFileCollectionItem(item) : item);
}
}
fileCollectionItems = await (0, maybeExpand_1.maybeExpand)(fileCollectionItems, options);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
(0, sortCollectionItems_1.sortCollectionItems)(fileCollectionItems);

@@ -81,0 +80,0 @@ return new FileCollection_1.FileCollection(fileCollectionItems);

import JSZip from 'jszip';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions } from './utilities/maybeFilter';
import { Options } from './Options';
export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];

@@ -11,4 +11,4 @@ /**

*/
export declare function fileCollectionFromZip(zipContent: ZipFileContent, options?: FilterOptions): Promise<FileCollection>;
export declare function fileCollectionItemsFromZip(zipContent: ZipFileContent): Promise<FileCollectionItem[]>;
export declare function fileCollectionFromZip(zipContent: ZipFileContent, options?: Options): Promise<FileCollection>;
export declare function fileCollectionItemsFromZip(zipContent: ZipFileContent, options?: Options): Promise<FileCollectionItem[]>;
//# sourceMappingURL=fileCollectionFromZip.d.ts.map

@@ -9,3 +9,3 @@ "use strict";

const FileCollection_1 = require("./FileCollection");
const maybeFilter_1 = require("./utilities/maybeFilter");
const shouldAddItem_1 = require("./utilities/shouldAddItem");
/**

@@ -17,8 +17,7 @@ * Create a FileCollection from a zip

async function fileCollectionFromZip(zipContent, options = {}) {
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent);
fileCollectionItems = await (0, maybeFilter_1.maybeFilter)(fileCollectionItems, options);
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent, options);
return new FileCollection_1.FileCollection(fileCollectionItems);
}
exports.fileCollectionFromZip = fileCollectionFromZip;
async function fileCollectionItemsFromZip(zipContent) {
async function fileCollectionItemsFromZip(zipContent, options = {}) {
const jsZip = new jszip_1.default();

@@ -31,3 +30,5 @@ const zip = await jsZip.loadAsync(zipContent);

continue;
fileCollectionItems.push({
if (!(0, shouldAddItem_1.shouldAddItem)(entry.name, options.filter))
continue;
const item = {
name: entry.name.replace(/^.*\//, ''),

@@ -48,4 +49,2 @@ relativePath: entry.name,

void entry.async('arraybuffer').then((arrayBuffer) => {
//todo the test are currently passing I don't know how to solve this
//@ts-expect-error to fix
controller.enqueue(arrayBuffer);

@@ -57,3 +56,4 @@ controller.close();

},
});
};
fileCollectionItems.push(item);
}

@@ -60,0 +60,0 @@ return fileCollectionItems;

{
"name": "filelist-utils",
"version": "1.9.0",
"version": "1.10.0",
"description": "Create a FileCollection from a path or a zip file",

@@ -48,18 +48,20 @@ "main": "./lib/index.js",

"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@types/jest": "^29.5.1",
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@types/jest": "^29.5.2",
"@types/pako": "^2.0.0",
"cheminfo-build": "^1.2.0",
"eslint": "^8.40.0",
"eslint": "^8.42.0",
"eslint-config-cheminfo-typescript": "^11.3.1",
"fifo-logger": "^0.6.1",
"jest": "^29.5.0",
"msw": "^1.2.1",
"msw": "^1.2.2",
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"typescript": "^5.0.4",
"rimraf": "^5.0.1",
"typescript": "^5.1.3",
"undici": "^5.22.1"
},
"dependencies": {
"cross-fetch": "^3.1.5",
"cheminfo-types": "^1.7.2",
"cross-fetch": "^3.1.6",
"jszip": "^3.10.1",

@@ -66,0 +68,0 @@ "pako": "^2.1.0"

@@ -1,6 +0,5 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { maybeExpand } from './utilities/maybeExpand';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';
import { Options } from './Options';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -20,3 +19,3 @@

fileList: FileList,
options: ExpandOptions & FilterOptions = {},
options: Options = {},
): Promise<FileCollection> {

@@ -26,3 +25,3 @@ let fileCollectionItems: FileCollectionItem[] = [];

for (const file of fileList) {
fileCollectionItems.push({
const item = {
name: file.name,

@@ -36,9 +35,8 @@ size: file.size,

stream: () => file.stream(),
});
};
fileCollectionItems.push(...(await expandAndFilter(item, options)));
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);
return new FileCollection(fileCollectionItems);
}

@@ -1,6 +0,5 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { maybeExpand } from './utilities/maybeExpand';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';
import { Options } from './Options';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -18,3 +17,3 @@

files: File[],
options: ExpandOptions & FilterOptions = {},
options: Options = {},
): Promise<FileCollection> {

@@ -24,3 +23,3 @@ let fileCollectionItems: FileCollectionItem[] = [];

for (const file of files) {
fileCollectionItems.push({
const item = {
name: file.name,

@@ -34,9 +33,8 @@ size: file.size,

stream: () => file.stream(),
});
};
fileCollectionItems.push(...(await expandAndFilter(item, options)));
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);
return new FileCollection(fileCollectionItems);
}

@@ -1,5 +0,4 @@

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { Options } from './Options';
import { fileCollectionFromPaths } from './fileCollectionFromPaths';
import { FilterOptions } from './utilities/maybeFilter';

@@ -14,5 +13,5 @@ /**

path: string,
options: ExpandOptions & FilterOptions = {},
options: Options = {},
): Promise<FileCollection> {
return fileCollectionFromPaths([path], options);
}

@@ -6,7 +6,6 @@ import { createReadStream } from 'node:fs';

import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { maybeExpand } from './utilities/maybeExpand';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';
import { Options } from './Options';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -22,3 +21,3 @@

paths: string[],
options: ExpandOptions & FilterOptions = {},
options: Options = {},
): Promise<FileCollection> {

@@ -29,7 +28,4 @@ let fileCollectionItems: FileCollectionItem[] = [];

const base = basename(path);
await appendFiles(fileCollectionItems, path, base);
await appendFiles(fileCollectionItems, path, base, options);
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);

@@ -43,2 +39,3 @@ return new FileCollection(fileCollectionItems);

base: string,
options: Options = {},
) {

@@ -51,8 +48,9 @@ const entries = await readdir(currentDir);

if (info.isDirectory()) {
await appendFiles(fileCollection, current, `${base}/${entry}`);
await appendFiles(fileCollection, current, `${base}/${entry}`, options);
} else {
fileCollection.push({
const relativePath = `${base}/${entry}`;
const item = {
name: entry,
size: info.size,
relativePath: `${base}/${entry}`,
relativePath,
lastModified: Math.round(info.mtimeMs),

@@ -76,5 +74,6 @@ text: (): Promise<string> => {

},
});
};
fileCollection.push(...(await expandAndFilter(item, options)));
}
}
}

@@ -7,8 +7,7 @@ import fetch from 'cross-fetch';

} from './CachedFileCollectionItem';
import { ExpandOptions } from './ExpandOptions';
import { FileCollection } from './FileCollection';
import { FileCollectionItem } from './FileCollectionItem';
import { Options } from './Options';
import { WebSource } from './WebSourceFile';
import { maybeExpand } from './utilities/maybeExpand';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';
import { expandAndFilter } from './utilities/expand/expandAndFilter';
import { sortCollectionItems } from './utilities/sortCollectionItems';

@@ -28,5 +27,3 @@

source: WebSource,
options: { baseURL?: string | URL } & CacheOptions &
ExpandOptions &
FilterOptions = {},
options: { baseURL?: string | URL } & CacheOptions & Options = {},
): Promise<FileCollection> {

@@ -68,3 +65,3 @@ const { baseURL, cache = false } = options;

const fileURL = new URL(entry.relativePath, realBaseURL);
const filecollectionItem = {
const item = {
name: entry.relativePath.split('/').pop() || '',

@@ -86,12 +83,12 @@ size,

};
fileCollectionItems.push(
cache
? new CachedFileCollectionItem(filecollectionItem)
: filecollectionItem,
);
const expanded = await expandAndFilter(item, options);
// we should be aware that we don't cache the zip file itself
for (const item of expanded) {
fileCollectionItems.push(
cache ? new CachedFileCollectionItem(item) : item,
);
}
}
fileCollectionItems = await maybeExpand(fileCollectionItems, options);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
sortCollectionItems(fileCollectionItems);
return new FileCollection(fileCollectionItems);
}

@@ -5,3 +5,4 @@ import JSZip from 'jszip';

import { FileCollectionItem } from './FileCollectionItem';
import { FilterOptions, maybeFilter } from './utilities/maybeFilter';
import { Options } from './Options';
import { shouldAddItem } from './utilities/shouldAddItem';

@@ -17,10 +18,15 @@ export type ZipFileContent = Parameters<typeof JSZip.loadAsync>[0];

zipContent: ZipFileContent,
options: FilterOptions = {},
options: Options = {},
): Promise<FileCollection> {
let fileCollectionItems = await fileCollectionItemsFromZip(zipContent);
fileCollectionItems = await maybeFilter(fileCollectionItems, options);
let fileCollectionItems = await fileCollectionItemsFromZip(
zipContent,
options,
);
return new FileCollection(fileCollectionItems);
}
export async function fileCollectionItemsFromZip(zipContent: ZipFileContent) {
export async function fileCollectionItemsFromZip(
zipContent: ZipFileContent,
options: Options = {},
) {
const jsZip = new JSZip();

@@ -32,3 +38,4 @@ const zip = await jsZip.loadAsync(zipContent);

if (entry.dir) continue;
fileCollectionItems.push({
if (!shouldAddItem(entry.name, options.filter)) continue;
const item = {
name: entry.name.replace(/^.*\//, ''),

@@ -49,4 +56,2 @@ relativePath: entry.name,

void entry.async('arraybuffer').then((arrayBuffer) => {
//todo the test are currently passing I don't know how to solve this
//@ts-expect-error to fix
controller.enqueue(arrayBuffer);

@@ -58,5 +63,6 @@ controller.close();

},
});
};
fileCollectionItems.push(item);
}
return fileCollectionItems;
}

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

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

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

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

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

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