All Projects → jaydenseric → extract-files

jaydenseric / extract-files

Licence: MIT license
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.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to extract-files

find-unused-exports
A Node.js CLI and equivalent JS API to find unused ECMAScript module exports in a project.
Stars: ✭ 30 (-37.5%)
Mutual labels:  esm, maintained, mjs
coverage-node
A simple CLI to run Node.js and report code coverage.
Stars: ✭ 39 (-18.75%)
Mutual labels:  esm, maintained, mjs
Aleph.js
The Full-stack Framework in Deno.
Stars: ✭ 3,448 (+7083.33%)
Mutual labels:  esm
nanobundle
Yet another build tool for libraries, powered by esbuild
Stars: ✭ 45 (-6.25%)
Mutual labels:  esm
loaders
ECMAScript Modules Loaders
Stars: ✭ 65 (+35.42%)
Mutual labels:  esm
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+683.33%)
Mutual labels:  esm
zodbpickle
Fork of Python's pickle module to work with ZODB
Stars: ✭ 16 (-66.67%)
Mutual labels:  maintained
Webpack
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
Stars: ✭ 60,034 (+124970.83%)
Mutual labels:  esm
oletus
Minimal ECMAScript Module test runner
Stars: ✭ 43 (-10.42%)
Mutual labels:  esm
motion-hooks
A simple Hooks wrapper over Motion One, An animation library, built on the Web Animations API for the smallest filesize and the fastest performance.
Stars: ✭ 93 (+93.75%)
Mutual labels:  esm
react-use-comlink
Three ways to use Comlink web workers through React Hooks (and in a typesafe manner).
Stars: ✭ 39 (-18.75%)
Mutual labels:  mjs
tailwind-layouts
Collection of Tailwind Layouts
Stars: ✭ 53 (+10.42%)
Mutual labels:  esm
atjson
atjson is a living content format for annotating content
Stars: ✭ 192 (+300%)
Mutual labels:  maintained
asis
ASIS (Advanced Social Image Search) indexes Flickr and Instagram images and provides a search API across both indexes.
Stars: ✭ 28 (-41.67%)
Mutual labels:  maintained
tape-es
ESM-compatible Tape.js test runner
Stars: ✭ 24 (-50%)
Mutual labels:  esm
Esm
Tomorrow's ECMAScript modules today!
Stars: ✭ 5,093 (+10510.42%)
Mutual labels:  esm
resolve-typescript-plugin
webpack plugin to resolve TypeScript files when importing with js file extension in ESM projects
Stars: ✭ 39 (-18.75%)
Mutual labels:  esm
nsplayer
A web player with shakaplayer & hls.js both supported
Stars: ✭ 23 (-52.08%)
Mutual labels:  esm
marky
A modular and extensible ESM and Deno Markdown parser.
Stars: ✭ 16 (-66.67%)
Mutual labels:  esm
nodekit
[Moved to Codeberg] A Small Web server.
Stars: ✭ 68 (+41.67%)
Mutual labels:  esm

extract-files

npm version CI status

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.

Used by GraphQL multipart request spec client implementations such as graphql-react and apollo-upload-client.

Installation

To install with npm, run:

npm install extract-files

See the documentation for the function extractFiles to get started.

Requirements

  • Node.js: ^12.22.0 || ^14.17.0 || >= 16.0.0
  • Browsers: > 0.5%, not OperaMini all, not IE > 0, not dead

Exports

These ECMAScript modules are published to npm and exported via the package.json exports field:

extractFiles.mjs

Export default

Function extractFiles — Recursively extracts 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.

Type parameters
  1. Extractable: any — Extractable file type.
Parameters
  1. value: unknown — Value to extract files from. Typically an object tree.
  2. isExtractable: (value: unknown) => value is Extractable — Matches extractable files. Typically isExtractableFile.
  3. path ?: ObjectPath — Prefix for object paths for extracted files. Defaults to "".
Returns

Extraction<Extractable> — Extraction result.

Example 1

Extracting files from an object.

For the following:

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:

{
  "a": null,
  "b": [null, null]
}

files is a Map instance containing:

Key Value
file1 ["prefix.a", "prefix.b.0"]
file2 ["prefix.b.1"]

Type Extraction

object — An extraction result.

Type parameters
  1. Extractable ?: any — Extractable file type. Defaults to unknown.
Properties
  • clone: unknown — Clone of the original value with files recursively replaced with null.
  • files: Map<Extractable, Array<ObjectPath>> — Extracted files and their object paths within the original value.

Type ObjectPath

string — String notation for the path to a node in an object tree.

See
Example 1

An object path for object property a, array index 0, object property b:

a.0.b

isExtractableFile.mjs

Export default

Function isExtractableFile — Checks if a value is an extractable file.

Parameters
  1. value: unknown — Value to check.
Returns

value is ExtractableFile — Is the value an extractable file.

Type ExtractableFile

File | Blob — An extractable file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].