Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Environment Support beside Browsers/React-Native #10

Closed
n1ru4l opened this issue Jul 23, 2019 · 2 comments
Closed

Optional Environment Support beside Browsers/React-Native #10

n1ru4l opened this issue Jul 23, 2019 · 2 comments

Comments

@n1ru4l
Copy link
Contributor

n1ru4l commented Jul 23, 2019

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?

@jaydenseric
Copy link
Owner

This is a nice idea :)

Consideration: If a consumer wants to just extend the default set with one more type of "file", they will have to copy and paste the defaults across into their own function, and both sets will appear in their bundle. Maybe if the default isFileValue() was exported, they could use it inside their custom function 🤔

@jaydenseric
Copy link
Owner

This enhancement has been published in v6.0.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants