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

@data-wrangling-components/utilities

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@data-wrangling-components/utilities - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

22

dist/cjs/common/FileCollection.js

@@ -7,3 +7,2 @@ "use strict";

require("core-js/modules/web.dom-collections.iterator.js");
var _ = require("..");
var _types = require("../types");

@@ -21,2 +20,8 @@ var _utils = require("../utils");

}
set config(config) {
this._config = {
...this._config,
...config
};
}
async _addFromZip(file) {

@@ -37,4 +42,3 @@ if (!this.name) {

file = (0, _utils).createFileWithPath(file, {
name,
type: _.FileMimeType[(0, _utils).extension(name)]
name
});

@@ -54,4 +58,3 @@ }

const file = (0, _utils).createFileWithPath(blob, {
name,
type: _.FileMimeType[(0, _utils).extension(name)]
name
});

@@ -81,3 +84,3 @@ return this._addFile(file);

let files = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this._files;
if (this.supportedFilesOnly) {
if (this._config.supportedFilesOnly) {
return files.filter((file)=>file.isSupported()

@@ -88,5 +91,2 @@ );

}
showOnlySupportedFiles(value) {
this.supportedFilesOnly = value;
}
list(type) {

@@ -183,6 +183,8 @@ let files = this._files;

this._files = [];
this.supportedFilesOnly = false;
this._name = '';
this._config = {
supportedFilesOnly: false
};
}
}
exports.FileCollection = FileCollection;

@@ -16,2 +16,3 @@ "use strict";

FileType["table"] = "table";
FileType["ipynb"] = "ipynb";
})(FileType || (exports.FileType = FileType = {}));

@@ -28,2 +29,3 @@ var FileMimeType;

FileMimeType["excel"] = 'application/vnd.ms-excel';
FileMimeType["ipynb"] = 'application/x-ipynb+json';
FileMimeType["folder"] = '';

@@ -37,2 +39,3 @@ FileMimeType['text/csv'] = 'csv';

FileMimeType['application/vnd.ms-excel'] = 'xlsx';
FileMimeType['application/x-ipynb+json'] = 'ipynb';
})(FileMimeType || (exports.FileMimeType = FileMimeType = {}));

@@ -48,2 +51,3 @@ var FileExtensions;

FileExtensions["arrow"] = '.arrow';
FileExtensions["ipynb"] = '.ipynb';
})(FileExtensions || (exports.FileExtensions = FileExtensions = {}));

@@ -12,2 +12,3 @@ "use strict";

exports.isSupportedFile = isSupportedFile;
exports.guessFileType = guessFileType;
exports.getDataURL = getDataURL;

@@ -18,2 +19,3 @@ exports.renameDuplicatedFiles = renameDuplicatedFiles;

require("core-js/modules/es.string.replace.js");
var _ = require("..");
var _common = require("../common");

@@ -23,3 +25,3 @@ var _types = require("../types");

name: 'File.txt',
type: 'text/plain',
type: _.FileMimeType.txt,
path: ''

@@ -74,7 +76,20 @@ };

exports.fetchFile = fetchFile;
function guessFileType(name) {
try {
const ext = extension(name);
const type = _.FileMimeType[ext];
if (type) {
return type;
}
} catch {
return fileDefaults.type;
}
return fileDefaults.type;
}
const createFile = (content, options)=>{
const { name , type } = {
const { name } = {
...fileDefaults,
...options
};
const type = (options === null || options === void 0 ? void 0 : options.type) || guessFileType(name);
return new File([

@@ -81,0 +96,0 @@ content

@@ -6,5 +6,4 @@ /*!

import "core-js/modules/web.dom-collections.iterator.js";
import { FileMimeType } from '..';
import { FileType } from '../types';
import { createFileWithPath, extension, fetchFile, getFilesFromZip, isZipFile, loadTable, renameDuplicatedFiles, tableToHTML, toZip } from '../utils';
import { createFileWithPath, fetchFile, getFilesFromZip, isZipFile, loadTable, renameDuplicatedFiles, tableToHTML, toZip } from '../utils';
import { BaseFile } from './BaseFile';

@@ -20,2 +19,8 @@ import { FileWithPath } from './FileWithPath';

}
set config(config) {
this._config = {
...this._config,
...config
};
}
async _addFromZip(file) {

@@ -36,4 +41,3 @@ if (!this.name) {

file = createFileWithPath(file, {
name,
type: FileMimeType[extension(name)]
name
});

@@ -53,4 +57,3 @@ }

const file = createFileWithPath(blob, {
name,
type: FileMimeType[extension(name)]
name
});

@@ -80,3 +83,3 @@ return this._addFile(file);

let files = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this._files;
if (this.supportedFilesOnly) {
if (this._config.supportedFilesOnly) {
return files.filter((file)=>file.isSupported()

@@ -87,5 +90,2 @@ );

}
showOnlySupportedFiles(value) {
this.supportedFilesOnly = value;
}
list(type) {

@@ -182,5 +182,7 @@ let files = this._files;

this._files = [];
this.supportedFilesOnly = false;
this._name = '';
this._config = {
supportedFilesOnly: false
};
}
}

@@ -10,2 +10,3 @@ export var FileType;

FileType["table"] = "table";
FileType["ipynb"] = "ipynb";
})(FileType || (FileType = {}));

@@ -21,2 +22,3 @@ export var FileMimeType;

FileMimeType["excel"] = 'application/vnd.ms-excel';
FileMimeType["ipynb"] = 'application/x-ipynb+json';
FileMimeType["folder"] = '';

@@ -30,2 +32,3 @@ FileMimeType['text/csv'] = 'csv';

FileMimeType['application/vnd.ms-excel'] = 'xlsx';
FileMimeType['application/x-ipynb+json'] = 'ipynb';
})(FileMimeType || (FileMimeType = {}));

@@ -40,2 +43,3 @@ export var FileExtensions;

FileExtensions["arrow"] = '.arrow';
FileExtensions["ipynb"] = '.ipynb';
})(FileExtensions || (FileExtensions = {}));

@@ -6,2 +6,3 @@ /*!

import "core-js/modules/es.string.replace.js";
import { FileMimeType } from '..';
import { BaseFile, FileWithPath } from '../common';

@@ -11,3 +12,3 @@ import { FileType } from '../types';

name: 'File.txt',
type: 'text/plain',
type: FileMimeType.txt,
path: ''

@@ -61,7 +62,20 @@ };

};
export function guessFileType(name) {
try {
const ext = extension(name);
const type = FileMimeType[ext];
if (type) {
return type;
}
} catch {
return fileDefaults.type;
}
return fileDefaults.type;
}
export const createFile = (content, options)=>{
const { name , type } = {
const { name } = {
...fileDefaults,
...options
};
const type = (options === null || options === void 0 ? void 0 : options.type) || guessFileType(name);
return new File([

@@ -68,0 +82,0 @@ content

@@ -9,8 +9,12 @@ /*!

import { FileWithPath } from './FileWithPath';
interface Config {
supportedFilesOnly?: boolean;
}
export declare class FileCollection {
private _files;
private supportedFilesOnly;
private _name;
private _config;
set name(name: string);
get name(): string;
set config(config: Config);
private _addFromZip;

@@ -23,3 +27,2 @@ private _addFile;

private filtered;
showOnlySupportedFiles(value: boolean): void;
list(type?: FileType): BaseFile[];

@@ -41,1 +44,2 @@ toDsv(name: string): Promise<string>;

}
export {};

@@ -13,3 +13,4 @@ /*!

arrow = "arrow",
table = "table"
table = "table",
ipynb = "ipynb"
}

@@ -24,2 +25,3 @@ export declare enum FileMimeType {

excel = "application/vnd.ms-excel",
ipynb = "application/x-ipynb+json",
folder = "",

@@ -32,3 +34,4 @@ 'text/csv' = "csv",

'application/x-arrow' = "arrow",
'application/vnd.ms-excel' = "xlsx"
'application/vnd.ms-excel' = "xlsx",
'application/x-ipynb+json' = "ipynb"
}

@@ -41,3 +44,4 @@ export declare enum FileExtensions {

zip = ".zip",
arrow = ".arrow"
arrow = ".arrow",
ipynb = ".ipynb"
}

@@ -20,2 +20,3 @@ /*!

export declare const fetchFile: (url: string) => Promise<Blob>;
export declare function guessFileType(name: string): string;
export declare const createFile: (content: Blob, options?: Omit<FileOptions, "path"> | undefined) => File;

@@ -22,0 +23,0 @@ export declare const createFileWithPath: (content: Blob, options?: FileOptions | undefined) => FileWithPath;

{
"name": "@data-wrangling-components/utilities",
"version": "1.4.0",
"version": "1.4.1",
"main": "dist/cjs/index.js",

@@ -5,0 +5,0 @@ "publishConfig": {

@@ -8,7 +8,5 @@ /*!

import ColumnTable from 'arquero/dist/types/table/column-table'
import { FileMimeType } from '..'
import { FileType, Json } from '../types'
import {
createFileWithPath,
extension,
fetchFile,

@@ -25,6 +23,11 @@ getFilesFromZip,

interface Config {
supportedFilesOnly?: boolean
}
export class FileCollection {
private _files: BaseFile[] = []
private supportedFilesOnly = false
private _name = ''
private _config: Config = {
supportedFilesOnly: false,
}

@@ -40,2 +43,6 @@ set name(name: string) {

set config(config: Config) {
this._config = { ...this._config, ...config }
}
private async _addFromZip(file: FileWithPath | File) {

@@ -52,6 +59,3 @@ if (!this.name) {

if (file instanceof File) {
file = createFileWithPath(file, {
name,
type: FileMimeType[extension(name) as keyof typeof FileMimeType],
})
file = createFileWithPath(file, { name })
}

@@ -68,6 +72,3 @@

const blob = await fetchFile(fileUrl)
const file = createFileWithPath(blob, {
name,
type: FileMimeType[extension(name) as keyof typeof FileMimeType],
})
const file = createFileWithPath(blob, { name })
return this._addFile(file)

@@ -97,3 +98,3 @@ }

private filtered(files = this._files): BaseFile[] {
if (this.supportedFilesOnly) {
if (this._config.supportedFilesOnly) {
return files.filter(file => file.isSupported())

@@ -104,6 +105,2 @@ }

showOnlySupportedFiles(value: boolean): void {
this.supportedFilesOnly = value
}
list(type?: FileType): BaseFile[] {

@@ -110,0 +107,0 @@ let files: BaseFile[] = this._files

@@ -15,2 +15,3 @@ /*!

table = 'table',
ipynb = 'ipynb',
}

@@ -26,2 +27,3 @@

excel = 'application/vnd.ms-excel',
ipynb = 'application/x-ipynb+json',
folder = '',

@@ -35,2 +37,3 @@ 'text/csv' = 'csv',

'application/vnd.ms-excel' = 'xlsx',
'application/x-ipynb+json' = 'ipynb',
}

@@ -45,2 +48,3 @@

arrow = '.arrow',
ipynb = '.ipynb',
}

@@ -6,3 +6,3 @@ /*!

import { isDsvFile, isJsonFile, isZipFile } from '..'
import { guessFileType, isDsvFile, isJsonFile, isZipFile } from '..'
import { BaseFile, FileWithPath } from '../../common'

@@ -54,2 +54,23 @@ import {

describe('guess file type', () => {
it('guess file type default', () => {
const filename = 'filename.pdf'
const expected = 'text/plain'
const result = guessFileType(filename)
expect(result).toEqual(expected)
})
it('guess file type with no extension', () => {
const filename = 'filename'
const expected = 'text/plain'
const result = guessFileType(filename)
expect(result).toEqual(expected)
})
it('guess file type json', () => {
const filename = 'filename.json'
const expected = 'application/json'
const result = guessFileType(filename)
expect(result).toEqual(expected)
})
})
describe('validates if the file name is .zip', () => {

@@ -56,0 +77,0 @@ it('isZipFile', () => {

@@ -6,2 +6,3 @@ /*!

import { FileMimeType } from '..'
import { BaseFile, FileWithPath } from '../common'

@@ -18,3 +19,3 @@ import { FileType, Json } from '../types'

name: 'File.txt',
type: 'text/plain',
type: FileMimeType.txt,
path: '',

@@ -73,2 +74,15 @@ }

export function guessFileType(name: string): string {
try {
const ext = extension(name)
const type = FileMimeType[ext as keyof typeof FileMimeType]
if (type) {
return type
}
} catch {
return fileDefaults.type
}
return fileDefaults.type
}
export const createFile = (

@@ -78,3 +92,4 @@ content: Blob,

): File => {
const { name, type } = { ...fileDefaults, ...options }
const { name } = { ...fileDefaults, ...options }
const type = options?.type || guessFileType(name)
return new File([content], name, { type })

@@ -81,0 +96,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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