Wrapped javascript object
Get attributes for a tag
Example:
<data>
<tag status="1">
<inner __type="s32">1</inner>
<inner __type="s32">2</inner>
</tag>
</data>
const data = {
tag: K.ATTR({ status: "1" }, {
inner: [
K.ITEM("s32", 1),
K.ITEM("s32", 2)
]
})
}
Eval:
$(data).attr("tag") // { status: "1" }
$(data).element("tag").attr().status // "1"
$(data).attr("tag.inner.0").__type // "s32"
Get a bigint value from a tag, convert to bigint if applicable.
Example:
<data>
<inner __type="s64">1</inner>
<inner __type="s32">2</inner>
<invalid __type="str">abc</invalid>
</data>
const data = {
inner: [
K.ITEM("s64", 1n),
K.ITEM("s32", 2)
],
invalid: K.ITEM("str", "abc")
}
Eval:
$(data).element("inner").bigint() // 1n
$(data).bigint("inner.1") // 2n
$(data).bigint("invalid", 3n) // 3n
Default return value when target path does not exists or is not valid.
Get a bigint array from a tag. Only returns valid arrays when target tag has a type of KBigIntType or KBigIntGroupType
Example:
<data>
<inner __type="s64" __count="2">1 2</inner>
<invalid __type="s32" __count="2">3 4</invalid>
</data>
const data = {
inner: K.ARRAY("s64", [1n, 2n]),
invalid: K.ARRAY("s32", [3, 4])
}
Eval:
$(data).bigints("inner") // [1n, 2n]
$(data).bigints("invalid") // undefined
Get a boolean value from a tag, return true only if value in the tag is number and greater than zero
Example:
<data>
<inner __type="bool">0</inner>
<inner __type="s32">2</inner>
</data>
const data = {
inner: [
K.ITEM("bool", false),
K.ITEM("s32", 2)
]
}
Eval:
$(data).bool("inner.0") // false
$(data).bool("inner.1") // true
$(data).bool("invalid") // false
Get a Buffer object from a tag, Only returns valid Buffer when target tag has a type of "bin"
Example:
<data>
<inner __type="bin">00ff</inner>
<invalid __type="u8" __count="3">1 2 3</invalid>
</data>
const data = {
inner: K.ITEM("bin", Buffer.from([0x00, 0xff])),
invalid: K.ARRAY("u8", [1, 2, 3])
}
Eval:
$(data).buffer("inner") // <Buffer 00 ff>
$(data).buffer("invalid") // undefined
Get raw content representation regardless of tag type
Example:
<data>
<number __type="s32">1</number>
<array __type="u8" __count="3">1 2 3</array>
<string __type="str">abc</string>
</data>
const data = {
number: K.ITEM("s32", 1),
array: K.ARRAY("u8", [1, 2, 3]),
string: K.ITEM("str", "abc")
}
Eval:
$(data).content("number") // [1]
$(data).content("array") // [1, 2, 3]
$(data).content("string") // "abc"
Get first element named path inside a tag
Example:
<data>
<inner>
<id __type="s32">1</id>
</inner>
<inner>
<id __type="s32">1</id>
</inner>
</data>
const data = {
inner: [
{ id: K.ITEM("s32", 1) },
{ id: K.ITEM("s32", 2) }
]
}
Eval:
$(data).element("inner") // <KDataReader>
$(data).element("inner").obj // { id: [object] }
$(data).element("inner").number("id") // 1
Get array of all elements named path inside a tag
Example:
<data>
<inner>
<id __type="s32">1</id>
</inner>
<inner>
<id __type="s32">1</id>
</inner>
</data>
const data = {
inner: [
{ id: K.ITEM("s32", 1) },
{ id: K.ITEM("s32", 2) }
]
}
Eval:
$(data).elements("inner") // [<KDataReader>, <KDataReader>]
$(data).elements("inner")[1].number("id") // 2
Get a number value from a tag, convert to number if applicable.
Example:
<data>
<inner __type="s64">1</inner>
<inner __type="s32">2</inner>
<invalid __type="str">abc</invalid>
</data>
const data = {
inner: [
K.ITEM("s64", 1n),
K.ITEM("s32", 2)
],
invalid: K.ITEM("str", "abc")
}
Eval:
$(data).element("inner").number() // 1
$(data).number("inner.1") // 2
$(data).number("invalid", 3) // 3
Default return value when target path does not exists or is not valid.
Get a number array from a tag. Only returns valid arrays when target tag has a type of KNumberType or KNumberGroupType
Example:
<data>
<inner __type="s64" __count="2">1 2</inner>
<invalid __type="s32" __count="2">3 4</invalid>
</data>
const data = {
invalid: K.ARRAY("s64", [1n, 2n]),
inner: K.ARRAY("s32", [3, 4])
}
Eval:
$(data).bigints("invalid") // undefined
$(data).bigints("inner") // [3, 4]
Get a string from a tag, Only returns valid string when target tag has a type of "str"
Example:
<data>
<inner __type="str">abc</inner>
<invalid __type="s32">1</invalid>
</data>
const data = {
inner: K.ITEM("str", "abc"),
invalid: K.ITEM("s32", 1)
}
Eval:
$(data).str("inner") // "abc"
$(data).str("invalid") // undefined
Generated using TypeDoc
A wrapper of javascript object for reading xml-like formatted data.