Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Sep 8, 2023
1 parent 5046710 commit d8af80f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 300 deletions.
152 changes: 2 additions & 150 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,157 +217,9 @@ thisIsAnIsomorphicFunction === fromJSON(serialized); // true
> It can only accept objects, functions and symbols and it doesn't actually
> serialize their values but only the string you used to identify the reference
## Supports

The following values are the only values accepted by `seroval`:

- Exact values
- `NaN`
- `Infinity`
- `-Infinity`
- `-0`
- Primitives
- `number`
- `string`
- `boolean`
- `null`
- `undefined`
- `bigint`
- `Array` + holes
- `Object`
- `RegExp`
- `Date`
- `Map`
- `Set`
- `Object.create(null)`
- `ArrayBuffer`
- `DataView`
- `TypedArray`
- `Int8Array`
- `Int16Array`
- `Int32Array`
- `Uint8Array`
- `Uint16Array`
- `Uint32Array`
- `Uint8ClampedArray`
- `Float32Array`
- `Float64Array`
- `BigInt64Array`
- `BigUint64Array`
- `Error`
- `AggregateError`
- `EvalError`
- `RangeError`
- `ReferenceError`
- `SyntaxError`
- `TypeError`
- `URIError`
- `Promise` (with `serializeAsync` and `toJSONAsync`)
- [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)
- [Well-known symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#static_properties)
- Web API
- [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
- [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
- [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) (with `serializeAsync` and `toJSONAsync`)
- [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) (with `serializeAsync` and `toJSONAsync`)
- [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
- [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
- If `FormData` has a `Blob`/`File` entry, it can only be serialized with `serializeAsync` and `toJSONAsync`
- Cyclic references (both self and mutual)
- Isomorphic references (a reference that exist on both the serializer and deserializer side)

## Compat

`serialize`, `serializeAsync`, `toJSON` and `toJSONAsync` can accept a `{ disabledFeatures: number }` option. The `disabledFeatures` defines how the output code would look like when serialized by `serialize`, `serializeAsync` and `compileJSON`.
## Docs

```js
import { serialize, Feature } from 'seroval';

const y = Object.create(null);
y.self = y;
y.example = 'Hello World';

function serializeWithTarget(value, disabledFeatures) {
const result = serialize(value, {
disabledFeatures,
});
console.log(result);
}

serializeWithTarget(y, Feature.ArrowFunction | Feature.ObjectAssign);
serializeWithTarget(y, 0);
```

```js
(function(h){return (h=Object.create(null),h.self=h,h.example="Hello World",h)})()
(h=>(h=Object.assign(Object.create(null),{example:"Hello World"}),h.self=h,h))()
```

`disabledFeatures` uses bit flags for faster checking, so if you need to disable multiple features, you can use the bitwise OR symbol (`|`).

Here's an `ES2017` flag:

```js
import { serialize, Feature } from 'seroval';

const ES2017FLAG =
Feature.AggregateError // ES2021
| Feature.BigInt // ES2020
| Feature.BigIntTypedArray // ES2020;

serialize(myValue, {
disabledFeatures: ES2017FLAG,
})
```

By default, all feature flags are enabled. The following are the feature flags and their behavior when disabled:

- [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
- Compiles down to `Error` instead.
- [`ArrayPrototypeValues`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
- Used for `Iterable`, uses `Symbol.iterator` instead.
- [`ArrowFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
- Uses function expressions for top-level and for deferred `Promise` values
- method shorthands (if `MethodShortand` is not set) or function expressions for `Iterable`.
- [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- Throws when attempted to use, includes `BigIntTypedArray`
- Disables use of `BigInt`, `BigInt64Array` and `BigUint64Array`
- [`ErrorPrototypeStack`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack)
- Skipped when detected.
- Affects both `Error` and `AggregateError`
- [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
- Throws when attempted to use.
- Disables serialization of `Map`
- [`MethodShorthand`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions)
- Uses function expressions instead.
- Only affects `Iterable`
- [`ObjectAssign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
- Uses manual object assignments instead.
- Affects `Iterable`, `Error`, `AggregateError` and `Object.create(null)`
- [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
- Throws when attempted to use in `serializeAsync` and `toJSONAsync`.
- Disables serialization of `Promise`
- [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
- Throws when attempted to use.
- Disables serialization of `Set`
- [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
- Throws when attempted to use.
- This disables serialization of well-known symbols and `Iterable`.
- [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
- Throws when attempted to use.
- Disables serialization of `TypedArray`
- [`BigIntTypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
- Throws when attempted to use
- Also throws if `BigInt` is disabled.
- Disables serialization of `BigInt64Array` and `BigUint64Array`
- `WebAPI`
- Throws and disables the following usage:
- [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
- [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
- [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
- [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File)
- [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
- [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
- [Compatibility](https://github.com/lxsmnsyc/seroval/blob/main/docs/compatibility.md)

## Sponsors

Expand Down
152 changes: 2 additions & 150 deletions packages/seroval/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,157 +217,9 @@ thisIsAnIsomorphicFunction === fromJSON(serialized); // true
> It can only accept objects, functions and symbols and it doesn't actually
> serialize their values but only the string you used to identify the reference
## Supports

The following values are the only values accepted by `seroval`:

- Exact values
- `NaN`
- `Infinity`
- `-Infinity`
- `-0`
- Primitives
- `number`
- `string`
- `boolean`
- `null`
- `undefined`
- `bigint`
- `Array` + holes
- `Object`
- `RegExp`
- `Date`
- `Map`
- `Set`
- `Object.create(null)`
- `ArrayBuffer`
- `DataView`
- `TypedArray`
- `Int8Array`
- `Int16Array`
- `Int32Array`
- `Uint8Array`
- `Uint16Array`
- `Uint32Array`
- `Uint8ClampedArray`
- `Float32Array`
- `Float64Array`
- `BigInt64Array`
- `BigUint64Array`
- `Error`
- `AggregateError`
- `EvalError`
- `RangeError`
- `ReferenceError`
- `SyntaxError`
- `TypeError`
- `URIError`
- `Promise` (with `serializeAsync` and `toJSONAsync`)
- [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)
- [Well-known symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#static_properties)
- Web API
- [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
- [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
- [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) (with `serializeAsync` and `toJSONAsync`)
- [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) (with `serializeAsync` and `toJSONAsync`)
- [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
- [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
- If `FormData` has a `Blob`/`File` entry, it can only be serialized with `serializeAsync` and `toJSONAsync`
- Cyclic references (both self and mutual)
- Isomorphic references (a reference that exist on both the serializer and deserializer side)

## Compat

`serialize`, `serializeAsync`, `toJSON` and `toJSONAsync` can accept a `{ disabledFeatures: number }` option. The `disabledFeatures` defines how the output code would look like when serialized by `serialize`, `serializeAsync` and `compileJSON`.
## Docs

```js
import { serialize, Feature } from 'seroval';

const y = Object.create(null);
y.self = y;
y.example = 'Hello World';

function serializeWithTarget(value, disabledFeatures) {
const result = serialize(value, {
disabledFeatures,
});
console.log(result);
}

serializeWithTarget(y, Feature.ArrowFunction | Feature.ObjectAssign);
serializeWithTarget(y, 0);
```

```js
(function(h){return (h=Object.create(null),h.self=h,h.example="Hello World",h)})()
(h=>(h=Object.assign(Object.create(null),{example:"Hello World"}),h.self=h,h))()
```

`disabledFeatures` uses bit flags for faster checking, so if you need to disable multiple features, you can use the logical OR symbol (`|`).

Here's an `ES2017` flag:

```js
import { serialize, Feature } from 'seroval';

const ES2017FLAG =
Feature.AggregateError // ES2021
| Feature.BigInt // ES2020
| Feature.BigIntTypedArray // ES2020;

serialize(myValue, {
disabledFeatures: ES2017FLAG,
})
```

By default, all feature flags are enabled. The following are the feature flags and their behavior when disabled:

- [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
- Compiles down to `Error` instead.
- [`ArrayPrototypeValues`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
- Used for `Iterable`, uses `Symbol.iterator` instead.
- [`ArrowFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
- Uses function expressions for top-level and for deferred `Promise` values
- method shorthands (if `MethodShortand` is not set) or function expressions for `Iterable`.
- [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- Throws when attempted to use, includes `BigIntTypedArray`
- Disables use of `BigInt`, `BigInt64Array` and `BigUint64Array`
- [`ErrorPrototypeStack`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack)
- Skipped when detected.
- Affects both `Error` and `AggregateError`
- [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
- Throws when attempted to use.
- Disables serialization of `Map`
- [`MethodShorthand`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions)
- Uses function expressions instead.
- Only affects `Iterable`
- [`ObjectAssign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
- Uses manual object assignments instead.
- Affects `Iterable`, `Error`, `AggregateError` and `Object.create(null)`
- [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
- Throws when attempted to use in `serializeAsync` and `toJSONAsync`.
- Disables serialization of `Promise`
- [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
- Throws when attempted to use.
- Disables serialization of `Set`
- [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
- Throws when attempted to use.
- This disables serialization of well-known symbols and `Iterable`.
- [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
- Throws when attempted to use.
- Disables serialization of `TypedArray`
- [`BigIntTypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
- Throws when attempted to use
- Also throws if `BigInt` is disabled.
- Disables serialization of `BigInt64Array` and `BigUint64Array`
- `WebAPI`
- Throws and disables the following usage:
- [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
- [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
- [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
- [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File)
- [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
- [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
- [Compatibility](https://github.com/lxsmnsyc/seroval/blob/main/docs/compatibility.md)

## Sponsors

Expand Down

0 comments on commit d8af80f

Please sign in to comment.