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

string-to-file

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-to-file

Transform string to file in client side

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

string-to-file

Transform string to file in client side.

Playground: https://string-to-file.js-bridge.com

Installation

$ yarn add string-to-file
$ npm install -S string-to-file

playground

git clone https://github.com/jerrywu001/string-to-file

npm i

npm run dev

Usage

  • json to file
import { stringToFile, saveFile } from 'string-to-file';

const json = {
  name: "jack",
  age: 12
};

const jsonFile = stringToFile(JSON.stringify(json, null, 2), 'xxx.json');

// download
saveFile(jsonFile);
  • string to file
import { stringToFile, saveFile } from 'string-to-file';

const string = `Hello world!

How are you!`;

const stringFile = stringToFile(string, 'xxx.txt');

// download
saveFile(stringFile);
  • script to file
import { stringToFile, saveFile } from 'string-to-file';

const jsString = `const a = 'Hello world!';

console.log(a);`;

const jsFile = stringToFile(jsString, 'xxx.js');

// download
saveFile(jsFile);

Utils

  • fileToBlob(file: File): Blob

  • saveFile(file: File, customFileName?: string): Promise<void>

  • blobToString(blob: Blob): Promise<string>

  • fileToString(file: File): Promise<string>

  • jsonToBase64(json: Record<string, any>): Promise<string>

  • stringToBase64(str: string, opts?: { forceEncode: boolean; fileType: FileType; }): string

  • base64ToFile(base64Url: string, filename: string): File

Keywords

FAQs

Package last updated on 09 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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