dist | ||
src | ||
.gitignore | ||
package-lock.json | ||
package.json | ||
README.md | ||
tsconfig.json |
serde-ts
a library for serializing and deserializing javascript objects
Usage
this library makes no assumptions about formats and loosely follows the architecture of Rust's serde crate. the major difference are the particular data types. serde-ts's internal data model contains the following types
serde-ts
data types
- null/undefined
- boolean
- number
- bigint
- string
- symbol
- function
- object
- iterable
- class
with the exception of iterables and classes, these types were chosen as they are the ones provided by Javascript's native typeof
operator which is used internally for type checking.
there are four interfaces which are relevant to serde-ts
users.
Serializer
a Serializer
is responsible for transforming the internal serde-ts
data model into the target serialization format. this means that it will have a serialize<Type>
function for each of serde-ts
's data types.
Deserializer
a Deserializer
is responsible for transforming the target serialization format into the internal serde-ts
data model. it will have a deserialize<Type>
for each of the serde-ts
's data types.
Serialize
Serialize
is responsible for transforming a value to the internal data model. for example, a Vector2
may be internally serialized as an iterable of numbers.
Deserialize
Deserialize
is responsible for transforming a value from the internal data model. it is the inverse of Serialize
. depending on the Deserialize
target, it may accept an iterable of numbers and produce a Vector2
.