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

fs-browsers

v2.1.1

Published

Usefull files functions for browsers and client side

Downloads

366

Readme

Fs Browsers

An easy to use files functions and api for browsers. In your client side code, you can easilly download any file by a url or even export anything you want to several types of files like txt, js, yml, csv, and even excel files.

GitHub package.json version (branch) GitHub issues GitHub GitHub repo file count npm bundle size

Whats New?

  • Add sheet title option to add title in the top of the sheet
  • Add option to override the default excel cells styles

Install

npm install fs-browsers

Download File

downloadFile(url, filename?) Download file based on url by the following code:

import { downloadFile } from 'fs-browsers';
// ...
downloadFile('url-to-file')

You can set the downloaded file name to anything you want like this:

import { downloadFile } from 'fs-browsers';
// ...
downloadFile('url-to-file', 'my-file.txt')

In some browsers the file name change might not work, read about HTTP Header Content-Disposition

Parameters

| Parameter | Type | Description | Required | Default | | ------ | ------ | ------ | ------ | ------ | | url | string | the url for downloading the wanted file | true | - | | fileName | string | the name of the file which will be downloaded | false | - |

Export File

exportFile(data, fileName?)

Export data or any text to a file using the following code:

import { exportFile } from 'fs-browsers';
//...
exportFile("this string will be exported to txt file");

The default file type is 'txt' but you can export to any file you want like this:

import { exportFile } from 'fs-browsers';
//...
exportFile("this string will be exported to js file", 'file-new-name.js');

Parameters

| Parameter | Type | Description | Required | Default | | ------ | ------ | ------ | ------ | ------ | | text | string | the text that will be exported to the file | true | - | | fileName | string | the name of the file which will be exported, including the suffix | false | file.txt |

exportCsvFile(data, fileName, headings?)

To export data to csv file use the following code:

import { exportCsvFile } from 'fs-browsers';
// ...
const data = [
    {
      firstName: 'John',
      lastName: 'Doe',
      age: 20,
    },
    {
      firstName: 'Peter',
      lastName: 'Parker',
      age: 30,
    },
    {
      firstName: 'Mark',
      lastName: 'Twain',
      age: 40,
    },
  ]
exportCsvFile(data);

You can override the csv headings by giving a headings list:

import { exportCsvFile } from 'fs-browsers';
// ...
const data = [
    {
      firstName: 'John',
      lastName: 'Doe',
      age: 20,
    },
    {
      firstName: 'Peter',
      lastName: 'Parker',
      age: 30,
    },
    {
      firstName: 'Mark',
      lastName: 'Twain',
      age: 40,
    },
  ]
const headings = ["First Name", "Last Name", "Age"];
exportCsvFile(data, 'name.csv', headings);

Parameters

| Parameter | Type | Description | Required | Default | | ------ | ------ | ------ | ------ | ------ | | data | {}[] | the array of data that will be exported into the Csv file | true | - | | fileName | string | the name of the Csv which will be exported, including the suffix | false | file.csv | | headings | string[] | array of string for the Csv headings row | false | null |

exportXlsxFile(data, fileName, options?)

To export data to Excel file ('xlsx') use the following code:

import { exportXlsxFile } from 'fs-browsers';
// ...
const data = [
    {
      firstName: 'John',
      lastName: 'Doe',
      age: 20,
    },
    {
      firstName: 'Peter',
      lastName: 'Parker',
      age: 30,
    },
    {
      firstName: 'Mark',
      lastName: 'Twain',
      age: 40,
    },
  ]
exportXlsxFile(data);

You can override the excel headings by giving a headings list:

import { exportXlsxFile } from 'fs-browsers';
const data = [
    {
      firstName: 'John',
      lastName: 'Doe',
      age: 20,
    },
    {
      firstName: 'Peter',
      lastName: 'Parker',
      age: 30,
    },
    {
      firstName: 'Mark',
      lastName: 'Twain',
      age: 40,
    },
  ]
const headings = ["First Name", "Last Name", "Age"];
exportXlsxFile(data, 'names.xlsx', { headings: headings });

You can add title to the excel sheet that will be presented above the data table:

import { exportXlsxFile } from 'fs-browsers';
const data = [
    {
      firstName: 'John',
      lastName: 'Doe',
      age: 20,
    },
    {
      firstName: 'Peter',
      lastName: 'Parker',
      age: 30,
    },
    {
      firstName: 'Mark',
      lastName: 'Twain',
      age: 40,
    },
  ]
const headings = ["First Name", "Last Name", "Age"];
const title = "People";
exportXlsxFile(data, 'names.xlsx', { headings: headings, sheetTitle: title });

It is very much the same as csv files in the code, but the result is a bit different. The Excel file has some simple design and the csv file has not. Moreover, xlsx files are more complex and functional then csv files.

The Excel file with the title looks like -Excel With Title Example

Parameters

| Parameter | Type | Description | Required | Default | | ------ | ------ | ------ | ------ | ------ | | data | {}[] | the array of data that will be exported into the Excel file | true | - | | fileName | string | the name of the Excel which will be exported, including the suffix | false | file.xlsx | | options | ExcelOptions | the advanced options of the Excel file| false | null |

Options

| Option | Type | Description | Required | Default | | ------ | ------ | ------ | ------ | ------ | | headings | string[] | array of string for the Excel headings row | false | null | | sheetName | string | the name of the sheet in the Excel | false | Sheet1 | | sheetTitle | string | title to be prensented in the top sheet above the data table | false | - | | cellStyle | CellStyle | style object to the data table cells as described in the xlsx-js-style package | false | defaultCellStyle | | headingStyle | CellStyle | style object to the data table heading cells as described in the xlsx-js-style package | false | defaultHeadingStyle | | titleStyle | CellStyle | style object to the sheet title cells as described in the xlsx-js-style package | false | defaultTitleStyle |

License

MIT