6.0.2 • Published 2 months ago

data-uri-to-buffer v6.0.2

Weekly downloads
4,271,359
License
MIT
Repository
github
Last release
2 months 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_samplesweetalert2-denazification@blackglory/node-fetchsystemjs-buildersemantic-release-gitmoji-action@ali5049/react-native-buttonssmart_one_connectsqip-demothird-party-lighthouse-audittoster-reporter-utiltoster-spec-reporter@damruravihara/react-native-testing-package@davidrockefeller/dosa-to-dana@datatypes/config@devidw/replika-diary-export@devprasant/learnstwitterbootstrapcsshong1-utils@ditojs/serveruimixuimohtml2amphtml2amp-devhtml2amp-gtaghtml2amp-vendedoreshtml2amp-vendors@akepinski/node-fetch@adembacaj/react-native-google-pay@adobe/asset-compute-pipeline@adobe/asset-compute-sdk@aabelmann/ui-layerstarbucks-jp-drinksteamhourapi@aysea/react-native-ui-library@azalpacir/react-native-dhp-printervision-camera-plugin-face-detectorvision-camera-base64-resizedilove-html2ampimage-color-limiterimage-sequencerinderight_node_studygriffin-ui-librarytest-library-123genz-native-elementstest-haptik-lib@amirdiafi/react-native-ios-haptics@amiruldev/wajs@anvilco/node-fetchget-pixelsget-pixels-browserget-pixels-frame-info-updateget-pixels-graphiteget-pixels-jpeg-js-upgradeget-pixels-tsget-pixels-updatedget-pixels-with-memory@classyllama/code-styleget-source@clicks/get-pixelstest-zeo-collect@cliqz-oss/systemjs-builder@cachier/cache-partialsgaurav-react-native-loop@cdevine49/react-numeric-inputtellonym-apiteapackage-tatespoorman297gamechanger-dapp-clitechnodromegamification-integration-new@boateo6/easy-mongo@bytelab/steamsearch@_nomtek/react-native-shimmer-animation@blusalt-sdk/react-native-blusalt-document-verification@blkmarketco/components-library@brantalikp/rn-resizejs_tooltipwifi_configuration_package
6.0.2

2 months ago

6.0.1

7 months ago

6.0.0

7 months ago

5.0.1

12 months ago

5.0.0

12 months ago

4.0.1

1 year ago

4.0.0

3 years ago

3.0.1

4 years ago

3.0.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.4

9 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago