![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Convert data of any type to text, json, formData, TypedArray, Blob, or ArrayBuffer
Convert data of any type to text, json, formData, TypedArray, Blob, or ArrayBuffer
npm install any-data
I needed a tool for dealing with the wide variety of data types that can be
passed to new Response()
. So AnyData
allows lazy data conversion for response
bodies to simplify http server middleware such as calculating etags and
compression with Brotli.
Note that AnyData
does not support ReadableStream
even though Response
does.
import { AnyData } from 'any-data';
await new AnyData('hello world').bytes(); // UTF-8 encoded in Uint8Array
await new AnyData(myArrayBuffer).bytes(); // Array buffer as Uint8Array
await new AnyData(myBlob).arrayBuffer(); // Blob as ArrayBuffer
import { AnyData } from 'any-data';
const hello = new AnyData('hello world');
// getting data
await hello.text(); // get data as text
await hello.json(); // get data as an object; will throw if data isn't valid JSON
await hello.arrayBuffer(); // get data as ArrayBuffer
await hello.blob(); // get data as Blob
await hello.bytes(); // get data as Uint8Array
await hello.formData(); // get data as FormData object
// setting data to something new
hello.set('foo bar');
// utility methods
hello.clone(); // returns a new AnyData object with a DEEP clone of the underlying data
hello.isEmpty(); // true if data is empty
hello.isSupported(); // true if data type is supported
hello.getDataCategory(); // Either bytes, text, or unknown
data type / method | text() | json() | formData() | bytes() | blob() | arrayBuffer() | clone() |
---|---|---|---|---|---|---|---|
null | "" | undefined | (empty) | (empty) | (empty) | (empty) | null |
string | itself | If valid JSON | If valid | Yes | Yes | Yes | itself |
Record<string, any> | JSON | itself | Yes | JSON | JSON | JSON | deep copy |
Array | JSON | itself | as entries | JSON | JSON | JSON | deep copy |
Response | text() | json() | formData() | bytes() | blob() | arrayBuffer() | clone() |
Blob | Yes | If valid JSON | If valid JSON | Yes | itself | Yes | deep copy |
ArrayBuffer | Yes | If valid JSON | If valid JSON | Yes | Yes | Yes | deep copy |
TypedArray | Yes | If valid JSON | If valid JSON | Yes | Yes | Yes | deep copy |
DataView | Yes | If valid JSON | If valid JSON | Yes | Yes | Yes | deep copy |
FormData † | Yes | Error | itself | Yes | Yes | Yes | deep copy |
ReadableStream | Yes | If valid JSON | If valid JSON | Yes | Yes | Yes | deep copy |
URLSearchParams | URL | entries | Yes | URL | URL | URL | deep copy |
† Note: all FormData is serialized to text with multi-part form boundary markers
Please open a ticket or PR on GitHub. All contributions are subject to the Code of Conduct.
1.0.3
FAQs
Convert data of any type to text, json, formData, TypedArray, Blob, or ArrayBuffer
The npm package any-data receives a total of 0 weekly downloads. As such, any-data popularity was classified as not popular.
We found that any-data demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.