6.0.2 • Published 2 years ago

data-uri-to-buffer v6.0.2

Weekly downloads
4,271,359
License
MIT
Repository
github
Last release
2 years ago

data-uri-to-buffer

Create an ArrayBuffer instance from a Data URI string

This module accepts a "data" URI String of data, and returns an ArrayBuffer instance with the decoded data.

This module is intended to work on a large variety of JavaScript runtimes, including Node.js and web browsers.

Example

import { dataUriToBuffer } from 'data-uri-to-buffer';

// plain-text data is supported
let uri = 'data:,Hello%2C%20World!';
let parsed = dataUriToBuffer(uri);
console.log(new TextDecoder().decode(parsed.buffer));
// 'Hello, World!'

// base64-encoded data is supported
uri = 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D';
parsed = dataUriToBuffer(uri);
console.log(new TextDecoder().decode(parsed.buffer));
// 'Hello, World!'

API

export interface ParsedDataURI {
	type: string;
	typeFull: string;
	charset: string;
	buffer: ArrayBuffer;
}

dataUriToBuffer(uri: string | URL) → ParsedDataURI

The type property gets set to the main type portion of the "mediatype" portion of the "data" URI, or defaults to "text/plain" if not specified.

The typeFull property gets set to the entire "mediatype" portion of the "data" URI (including all parameters), or defaults to "text/plain;charset=US-ASCII" if not specified.

The charset property gets set to the Charset portion of the "mediatype" portion of the "data" URI, or defaults to "US-ASCII" if the entire type is not specified, or defaults to "" otherwise.

Note: If only the main type is specified but not the charset, e.g. "data:text/plain,abc", the charset is set to the empty string. The spec only defaults to US-ASCII as charset if the entire type is not specified.

get-uri@next/react-dev-overlayeasy-select-rn@richienb/node-fetch-beta-test-14-03-2020@ptomato/node-fetch@piyushmishra/criticalrevisit-tetherrevisit-validatorreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutils@oiti/documentoscopy-react-nativeqwackbotquoc-testwidget-engineluminos-ui-core@everything-registry/sub-chunk-1445jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplegriffin-ui-librarysystemjs-buildertest-library-123test-haptik-libvulpesweb-print-escposwifi_configuration_packagexhynode-fetchtechnodrometeapackage-tatespoorman297tellonym-apistarbucks-jp-drinksteamhourapitest-zeo-collectsweetalert2-denazificationthird-party-lighthouse-auditvision-camera-plugin-face-detectorvision-camera-base64-resizedvantiq-reactvue-dev-clone@bytelab/steamsearch@blkmarketco/components-library@praella/localisationistjeuxuijrennsoh88-react-native-scroll-indicatorjs_tooltipjesh-calculationjnf-accesscontrol-rnttljordy-frijters-test-libkashyap-tg-apikhaled-salem-custom-componentskydrailove-html2ampimage-sequencerimage-color-limiterinderight_node_studyhong1-utilshtml2amp-vulcanhtml2amphtml2amp-devhtml2amp-gtaghtml2amp-vendedoreshtml2amp-vendorsh5-hala-widget-newlibre-office-flashcardskunkun-ext-imgur-uploadkoishi-plugin-henrik-valorant@w3cub/electron-fetch@web-std/fetch@trusttechnologies/identityprovider_sdk@tlgeo/react-native-gdal@thinxviewx/core-rn@typenode/node-fetch@testim/testim-cli@testim/testim-cli-dev@zotasys/nativeaerender-core-gliaagent-get-agentadcashawesome-module-kdarraylast-discordash07-currency-converterarchlibraryarvm-bestdeveloper@classyllama/code-style@cliqz-oss/systemjs-builder128981semzub@clicks/get-pixels@aysea/react-native-ui-library@azalpacir/react-native-dhp-printer@aabelmann/ui-layer@0xclearview/svelte-tiny-virtual-table@hankfc/stencil-starter@abhinavoneuipoc/stencil-test@_nomtek/react-native-shimmer-animation@ahmed_shaban123/react-native-currencyinput
6.0.2

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.1

3 years ago

4.0.0

4 years ago

3.0.1

5 years ago

3.0.0

6 years ago

2.0.2

6 years ago

2.0.1

7 years ago

2.0.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.4

10 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago