serialized
Serialize and deserialize javascript objects into compact, url encoded strings. Useful when you have to store rich objects (such as ElasticSearch queries) in browser url.
Example
// Describe field typesconst ProductField = const PriceRange = { } const TermOrWildcard = const boolType = const Query = const Search = // Complex queryconst search = from: 15 size: 100 query: bool: must: bool: should: wildcard: name: '*tablet*' term: category: 'Electronics/Tablets' bool: should: bool: must: term: manufacturer: 'Apple' range: price: gte: 0 lte: 1000 bool: must: term: manufacturer: 'Samsung' range: price: gte: 0 lte: 500 // Serialize objectconst serializedString = Search//=> f$1323111*tablet*$$03Electronics%2FTablets$$$313204Apple$$20$1000$$$3204Samsung$$20$500 Search//=> equals to 'search'
API
stringType([length])
Simple string. By default serializes strings with encodeURIComponent
length
Accept only strings with providedlength
integerType([max])
Positive integer
max
Accept only integers between0
andmax
numberType()
Simple number
constant(value)
value
Any javascript primitive type
objectOf(schema)
schema
Object withtoken
type values
const Person =
mapOf(keyToken, valueToken)
Javascript object as map
keyToken
Type of map keysvalueToken
Type of map values
oneOfType(tokens)
Union type
tokens
Array of possible types
const OptionalString =
arrayOfType(token, [length])
token
Type of array itemlength
Accept only arrays with providedlength
const Matrix =
template(callback)
const nullableType = const NullableString =
withCalculatedType(getType, callback)
Utility for deferred type calculation