mirror of
https://github.com/flynx/serialize.js.git
synced 2026-07-10 11:10:57 +00:00
docs and tests...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
439a68eeb7
commit
6f9eb29957
@ -48,10 +48,54 @@ var debug = {
|
||||
// string - string to use for indenting
|
||||
//
|
||||
//
|
||||
// serialize(obj, path, seen, indent, depth)
|
||||
// serialize(obj, base_path, seen, indent, depth)
|
||||
// -> str
|
||||
//
|
||||
//
|
||||
// Paths
|
||||
// A path is a chain of indexes/keys leading to a specific object in
|
||||
// tree.
|
||||
//
|
||||
// the root object is referenced by an empty path array.
|
||||
//
|
||||
// For sets, positional indexes are used, i.e. a set is treated like
|
||||
// an array ov values.
|
||||
//
|
||||
// For maps a two number index is used with the first being the position
|
||||
// of the item and the second indicated if the target is the key or the
|
||||
// value. i.e. a map is treated like an array of key value pairs.
|
||||
//
|
||||
//
|
||||
// Examples:
|
||||
// Object paths
|
||||
// ---------------------------------------------------------------
|
||||
// obj = [ <- []
|
||||
// null, <- [0]
|
||||
// [
|
||||
// 'a',
|
||||
// 'b', <- [1, 1]
|
||||
// 'c',
|
||||
// ],
|
||||
// Set([
|
||||
// 1,
|
||||
// 2,
|
||||
// 3, <- [2, 2]
|
||||
// ]),
|
||||
// Map([i <- [3] +----- index of elemnt in map
|
||||
// [ / +--- 0 means key
|
||||
// 'key', <- [3, 0, 0]
|
||||
// 'value' <- [3, 0, 1]
|
||||
// ], +--- 1 means value
|
||||
// [
|
||||
// [
|
||||
// 123 <- [3, 1, 0, 0]
|
||||
// ],
|
||||
// 'got tired of thinking up names',
|
||||
// ],
|
||||
// ]),
|
||||
// ]
|
||||
//
|
||||
//
|
||||
// XXX add function support...
|
||||
// XXX need to destinguish between map key and value in path...
|
||||
// XXX BUG: using non-whitespace as indent breaks the depth of the first
|
||||
|
||||
10
test.js
10
test.js
@ -57,14 +57,12 @@ test.Modifiers({
|
||||
return `[${ setup }]` },
|
||||
'object-stuffed': function(assert, setup){
|
||||
return `{"key":${ setup }}` },
|
||||
//* XXX need better indexing...
|
||||
// .getItem(..) / .setItem(..) break on recursive structures
|
||||
// in maps/sets...
|
||||
'map-stuffed': function(assert, setup){
|
||||
return `Map([["key",${ setup }],[${ setup },"value"]])` },
|
||||
'set-stuffed': function(assert, setup){
|
||||
return `Set([${ setup }])` },
|
||||
//*/
|
||||
'map-key-stuffed': function(assert, setup){
|
||||
return `Map([[${ setup },"value"]])` },
|
||||
'map-value-stuffed': function(assert, setup){
|
||||
return `Map([["key",${ setup }]])` },
|
||||
})
|
||||
|
||||
test.Tests({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user