8000 Optional Environment Support beside Browsers/React-Native · Issue #10 · jaydenseric/extract-files · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Optional Environment Support beside Browsers/React-Native #10
Closed
@n1ru4l

Description

@n1ru4l

I know that this package is intended for browser/react-native environments.

By adding a new parameter for extractFiles, e.g. isFileValue: (value: unknown) => boolean, other higher level implementations that are not browser-specific could also leverage the logic of this package.

This is how I would imagine a Node.js implementation that uses fs.ReadStream.

"use strict";

const fs = require("fs");
const extractFiles = require("extract-files");

function isFileValue(value) {
  return value instanceof fs.ReadStream;
}

const { clone, files } = extractFiles(input, "", isFileValue);

The isFileValue function would then (if defined) used instead of the code block here:

if (
(typeof File !== 'undefined' && value instanceof File) ||
(typeof Blob !== 'undefined' && value instanceof Blob) ||
value instanceof ReactNativeFile
) {

The default value stays the same.

function defaultIsFileValue(value) {
  return (
    (typeof File !== 'undefined' && value instanceof File) ||
    (typeof Blob !== 'undefined' && value instanceof Blob) ||
    value instanceof ReactNativeFile
  )
}

@jaydenseric What is your opinion on this? Are there any concerns? Would the impact on the bundle size be too huge? Could you imagine such a feature becoming part of this package and would you accept a pull request that implements this feature?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0