npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nexusapp/extract-files

v9.0.4

Published

Clones a value, recursively extracting File, Blob and ReactNativeFile instances with their object paths, replacing them with null. FileList instances are treated as File instance arrays.

Downloads

165

Readme

Fork of extract-files that supports Absinthe.Plug (absinthe_plug)

npm version CI status

Clones a value, recursively extracting File, Blob and ReactNativeFile instances with their object paths, replacing them with null. FileList instances are treated as File instance arrays.

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

Setup

Install with npm:

npm install extract-files

See the extractFiles documentation to get started.

Support

API

Table of contents

class ReactNativeFile

Used to mark a React Native File substitute in an object tree for extractFiles. It’s too risky to assume all objects with uri, type and name properties are files to extract.

| Parameter | Type | Description | | :-- | :-- | :-- | | file | ReactNativeFileSubstitute | A React Native File substitute. |

Examples

Ways to import.

import { ReactNativeFile } from 'extract-files';
import ReactNativeFile from 'extract-files/public/ReactNativeFile.js';

Ways to require.

const { ReactNativeFile } = require('extract-files');
const ReactNativeFile = require('extract-files/public/ReactNativeFile');

An extractable file in React Native.

import { ReactNativeFile } from 'extract-files';

const file = new ReactNativeFile({
  uri: uriFromCameraRoll,
  name: 'a.jpg',
  type: 'image/jpeg',
});

function extractFiles

Clones a value, recursively extracting File, Blob and ReactNativeFile instances with their object paths, replacing them with null. FileList instances are treated as File instance arrays.

| Parameter | Type | Description | | :-- | :-- | :-- | | value | * | Value (typically an object tree) to extract files from. | | path | ObjectPath? = '' | Prefix for object paths for extracted files. | | isExtractableFile | ExtractableFileMatcher? = isExtractableFile | The function used to identify extractable files. | | parentAddFile | Map? | Parent's addFile function. |

Returns: ExtractFilesResult — Result.

Examples

Ways to import.

import { extractFiles } from 'extract-files';
import extractFiles from 'extract-files/public/extractFiles.js';

Ways to require.

const { extractFiles } = require('extract-files');
const extractFiles = require('extract-files/public/extractFiles');

Extract files from an object.

For the following:

import { extractFiles } from 'extract-files';

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, 'prefix');

value remains the same.

clone is:

{
  "a": "0",
  "b": ["0", "1"]
}

files is a Map instance containing:

| Key | Value | | :------ | :---------------------------------- | | file1 | ['0', ['prefix.a', 'prefix.b.0']] | | file2 | ['1', ['prefix.b.1']] |


function isExtractableFile

Checks if a value is an extractable file.

Type: ExtractableFileMatcher

| Parameter | Type | Description | | :-------- | :--- | :-------------- | | value | * | Value to check. |

Returns: boolean — Is the value an extractable file.

Examples

Ways to import.

import { isExtractableFile } from 'extract-files';
import isExtractableFile from 'extract-files/public/isExtractableFile.js';

Ways to require.

const { isExtractableFile } = require('extract-files');
const isExtractableFile = require('extract-files/public/isExtractableFile');

type ExtractableFile

An extractable file.

Type: File | Blob | ReactNativeFile


type ExtractableFileMatcher

A function that checks if a value is an extractable file.

Type: Function

| Parameter | Type | Description | | :-------- | :--- | :-------------- | | value | * | Value to check. |

Returns: boolean — Is the value an extractable file.

See

Examples

How to check for the default exactable files, as well as a custom type of file.

import { isExtractableFile } from 'extract-files';

const isExtractableFileEnhanced = (value) =>
  isExtractableFile(value) ||
  (typeof CustomFile !== 'undefined' && value instanceof CustomFile);

type ExtractFilesResult

What extractFiles returns.

Type: object

| Property | Type | Description | | :-- | :-- | :-- | | clone | * | Clone of the original input value with files recursively replaced with null. | | files | Map<ExtractableFile, Array<ObjectPath>> | Extracted files and their locations within the original value. |


type ObjectPath

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

Type: string

See

Examples

Object path is property a, array index 0, object property b.

a.0.b

type ReactNativeFileSubstitute

A React Native File substitute for when using FormData.

Type: object

| Property | Type | Description | | :------- | :------ | :----------------- | | uri | string | Filesystem path. | | name | string? | File name. | | type | string? | File content type. |

See

Examples

A camera roll file.

const fileSubstitute = {
  uri: uriFromCameraRoll,
  name: 'a.jpg',
  type: 'image/jpeg',
};