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

extract-files

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-files - npm Package Compare versions

Comparing version 12.0.0 to 13.0.0

32

package.json
{
"name": "extract-files",
"version": "12.0.0",
"version": "13.0.0",
"description": "A function to recursively extract files and their object paths within a value, replacing them with null in a deep clone without mutating the original value. FileList instances are treated as File instance arrays. Files are typically File and Blob instances.",

@@ -36,25 +36,19 @@ "license": "MIT",

"engines": {
"node": "^12.22.0 || ^14.17.0 || >= 16.0.0"
"node": "^14.17.0 || ^16.0.0 || >= 18.0.0"
},
"browserslist": "Node 12.22 - 13 and Node < 13, Node 14.17 - 15 and Node < 15, Node >= 16, > 0.5%, not OperaMini all, not IE > 0, not dead",
"browserslist": "Node 14.17 - 15 and Node < 15, Node 16 - 17 and Node < 17, Node >= 18, > 0.5%, not OperaMini all, not dead",
"dependencies": {
"is-plain-obj": "^4.0.0"
"is-plain-obj": "^4.1.0"
},
"devDependencies": {
"@types/node": "^17.0.8",
"coverage-node": "^5.0.1",
"esbuild": "^0.14.11",
"eslint": "^8.6.0",
"eslint-config-env": "^23.0.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-compat": "^4.0.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsdoc": "^37.6.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"@types/node": "^18.7.13",
"coverage-node": "^8.0.0",
"esbuild": "^0.15.5",
"eslint": "^8.23.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"gzip-size": "^7.0.0",
"prettier": "^2.5.1",
"revertable-globals": "^3.0.0",
"test-director": "^8.0.1",
"typescript": "^4.6.0-dev.20220110"
"prettier": "^2.7.1",
"revertable-globals": "^4.0.0",
"test-director": "^10.0.0",
"typescript": "^4.8.2"
},

@@ -61,0 +55,0 @@ "scripts": {

# extract-files
[![npm version](https://badgen.net/npm/v/extract-files)](https://npm.im/extract-files) [![CI status](https://github.com/jaydenseric/extract-files/workflows/CI/badge.svg)](https://github.com/jaydenseric/extract-files/actions)
A function to recursively extract files and their object paths within a value, replacing them with `null` in a deep clone without mutating the original value. [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/Filelist) instances are treated as [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) instance arrays. Files are typically [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) and [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) instances.

@@ -11,3 +9,3 @@

To install with [npm](https://npmjs.com/get-npm), run:
For [Node.js](https://nodejs.org), to install [`extract-files`](https://npm.im/extract-files) with [npm](https://npmjs.com/get-npm), run:

@@ -18,119 +16,35 @@ ```sh

See the documentation for the function [`extractFiles`](#exports-extractFiles.mjs-export-default) to get started.
For [Deno](https://deno.land) and browsers, an example import map:
## Requirements
- [Node.js](https://nodejs.org): `^12.22.0 || ^14.17.0 || >= 16.0.0`
- [Browsers](https://npm.im/browserslist): `> 0.5%, not OperaMini all, not IE > 0, not dead`
## Exports
These ECMAScript modules are published to [npm](https://npmjs.com) and exported via the [`package.json`](./package.json) `exports` field:
- [`extractFiles.mjs`](#exports-extractFiles.mjs)
- [`isExtractableFile.mjs`](#exports-isExtractableFile.mjs)
### <span id="exports-extractFiles.mjs">[`extractFiles.mjs`](./extractFiles.mjs)</span>
#### <span id="exports-extractFiles.mjs-export-default">Export `default`</span>
Function `extractFiles` — Recursively extracts files and their [object paths](#exports-extractFiles.mjs-type-ObjectPath) within a value, replacing them with `null` in a deep clone without mutating the original value. [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/Filelist) instances are treated as [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) instance arrays.
##### <span id="exports-extractFiles.mjs-export-default-type-parameters">Type parameters</span>
1. `Extractable`: `any` — Extractable file type.
##### <span id="exports-extractFiles.mjs-export-default-parameters">Parameters</span>
1. `value`: `unknown` — Value to extract files from. Typically an object tree.
2. `isExtractable`: `(value: unknown) => value is Extractable` — Matches extractable files. Typically [`isExtractableFile`](#exports-isExtractableFile.mjs-export-default).
3. `path` `?`: [`ObjectPath`](#exports-extractFiles.mjs-type-ObjectPath) — Prefix for object paths for extracted files. Defaults to `""`.
##### <span id="exports-extractFiles.mjs-export-default-returns">Returns</span>
[`Extraction`](#exports-extractFiles.mjs-type-Extraction)<`Extractable`> — Extraction result.
##### <span id="exports-extractFiles.mjs-export-default-example-1">Example 1</span>
Extracting files from an object.
For the following:
```js
import extractFiles from "extract-files/extractFiles.mjs";
import isExtractableFile from "extract-files/isExtractableFile.mjs";
const file1 = new File(["1"], "1.txt", { type: "text/plain" });
const file2 = new File(["2"], "2.txt", { type: "text/plain" });
const value = {
a: file1,
b: [file1, file2],
};
const { clone, files } = extractFiles(value, isExtractableFile, "prefix");
```
`value` remains the same.
`clone` is:
```json
{
"a": null,
"b": [null, null]
"imports": {
"extract-files/": "https://unpkg.com/extract-files@13.0.0/",
"is-plain-obj": "https://unpkg.com/is-plain-obj@4.1.0/index.js",
"is-plain-obj/": "https://unpkg.com/is-plain-obj@4.1.0/"
}
}
```
`files` is a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance containing:
See the function [`extractFiles`](./extractFiles.mjs) to get started.
| Key | Value |
| :------ | :--------------------------- |
| `file1` | `["prefix.a", "prefix.b.0"]` |
| `file2` | `["prefix.b.1"]` |
## Requirements
#### <span id="exports-extractFiles.mjs-type-Extraction">Type `Extraction`</span>
Supported runtime environments:
`object` — An extraction result.
- [Node.js](https://nodejs.org) versions `^14.17.0 || ^16.0.0 || >= 18.0.0`.
- [Deno](https://deno.land), importing from a CDN that might require an import map for dependencies.
- Browsers matching the [Browserslist](https://browsersl.ist) query [`> 0.5%, not OperaMini all, not dead`](https://browsersl.ist/?q=%3E+0.5%25%2C+not+OperaMini+all%2C+not+dead).
##### <span id="exports-extractFiles.mjs-type-Extraction-type-parameters">Type parameters</span>
Non [Deno](https://deno.land) projects must configure [TypeScript](https://typescriptlang.org) to use types from the ECMAScript modules that have a `// @ts-check` comment:
1. `Extractable` `?`: `any` — Extractable file type. Defaults to `unknown`.
- [`compilerOptions.allowJs`](https://typescriptlang.org/tsconfig#allowJs) should be `true`.
- [`compilerOptions.maxNodeModuleJsDepth`](https://typescriptlang.org/tsconfig#maxNodeModuleJsDepth) should be reasonably large, e.g. `10`.
- [`compilerOptions.module`](https://typescriptlang.org/tsconfig#module) should be `"node16"` or `"nodenext"`.
##### <span id="exports-extractFiles.mjs-type-Extraction-properties">Properties</span>
## Exports
- `clone`: `unknown` — Clone of the original value with files recursively replaced with `null`.
- `files`: `Map`<`Extractable`, `Array`<[`ObjectPath`](#exports-extractFiles.mjs-type-ObjectPath)>> — Extracted files and their object paths within the original value.
The [npm](https://npmjs.com) package [`extract-files`](https://npm.im/extract-files) features [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design). It doesn’t have a main index module, so use deep imports from the ECMAScript modules that are exported via the [`package.json`](./package.json) field [`exports`](https://nodejs.org/api/packages.html#exports):
#### <span id="exports-extractFiles.mjs-type-ObjectPath">Type `ObjectPath`</span>
`string` — String notation for the path to a node in an object tree.
##### <span id="exports-extractFiles.mjs-type-ObjectPath-see">See</span>
- [`object-path` on npm](https://npm.im/object-path).
##### <span id="exports-waterfallRender.mjs-type-ObjectPath-example-1">Example 1</span>
An object path for object property `a`, array index `0`, object property `b`:
```
a.0.b
```
### <span id="exports-isExtractableFile.mjs">[`isExtractableFile.mjs`](./isExtractableFile.mjs)</span>
#### <span id="exports-isExtractableFile.mjs-export-default">Export `default`</span>
Function `isExtractableFile` — Checks if a value is an [extractable file](#exports-isExtractableFile.mjs-type-ExtractableFile).
##### <span id="exports-isExtractableFile.mjs-export-default-parameters">Parameters</span>
1. `value`: `unknown` — Value to check.
##### <span id="exports-isExtractableFile.mjs-export-default-returns">Returns</span>
`value is` [`ExtractableFile`](#exports-isExtractableFile.mjs-type-ExtractableFile) — Is the value an [extractable file](#exports-isExtractableFile.mjs-type-ExtractableFile).
#### <span id="exports-isExtractableFile.mjs-type-ExtractableFile">Type `ExtractableFile`</span>
[`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) | [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) — An extractable file.
- [`extractFiles.mjs`](./extractFiles.mjs)
- [`isExtractableFile.mjs`](./isExtractableFile.mjs)

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