updated jsvm types
This commit is contained in:
parent
262e78c04e
commit
c8776b7cd9
|
|
@ -313,7 +313,7 @@ func baseBinds(vm *goja.Runtime) {
|
||||||
vm.Set("toBytes", func(raw any, maxReaderBytes int) ([]byte, error) {
|
vm.Set("toBytes", func(raw any, maxReaderBytes int) ([]byte, error) {
|
||||||
switch v := raw.(type) {
|
switch v := raw.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return nil, nil
|
return []byte{}, nil
|
||||||
case string:
|
case string:
|
||||||
return []byte(v), nil
|
return []byte(v), nil
|
||||||
case []byte:
|
case []byte:
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func TestBaseBindsToBytes(t *testing.T) {
|
||||||
Value any
|
Value any
|
||||||
Expected []byte
|
Expected []byte
|
||||||
}{
|
}{
|
||||||
{"null", nil, nil},
|
{"null", nil, []byte{}},
|
||||||
{"string", "test", []byte("test")},
|
{"string", "test", []byte("test")},
|
||||||
{"number", -12.4, []byte("-12.4")},
|
{"number", -12.4, []byte("-12.4")},
|
||||||
{"bool", true, []byte("true")},
|
{"bool", true, []byte("true")},
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -186,8 +186,11 @@ declare function readerToString(reader: any, maxBytes?: number): string;
|
||||||
* // io.Reader
|
* // io.Reader
|
||||||
* const ex1 = toString(e.request.body)
|
* const ex1 = toString(e.request.body)
|
||||||
*
|
*
|
||||||
* // slice of bytes ("hello")
|
* // slice of bytes
|
||||||
* const ex2 = toString([104 101 108 108 111])
|
* const ex2 = toString([104 101 108 108 111]) // "hello"
|
||||||
|
*
|
||||||
|
* // null
|
||||||
|
* const ex3 = toString(null) // ""
|
||||||
* ` + "```" + `
|
* ` + "```" + `
|
||||||
*
|
*
|
||||||
* @group PocketBase
|
* @group PocketBase
|
||||||
|
|
@ -213,7 +216,10 @@ declare function toString(val: any, maxBytes?: number): string;
|
||||||
* const ex2 = toBytes("hello") // [104 101 108 108 111]
|
* const ex2 = toBytes("hello") // [104 101 108 108 111]
|
||||||
*
|
*
|
||||||
* // object (the same as the string '{"test":1}')
|
* // object (the same as the string '{"test":1}')
|
||||||
* const ex2 = toBytes({"test":1}) // [123 34 116 101 115 116 34 58 49 125]
|
* const ex3 = toBytes({"test":1}) // [123 34 116 101 115 116 34 58 49 125]
|
||||||
|
*
|
||||||
|
* // null
|
||||||
|
* const ex4 = toBytes(null) // []
|
||||||
* ` + "```" + `
|
* ` + "```" + `
|
||||||
*
|
*
|
||||||
* @group PocketBase
|
* @group PocketBase
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue