add exists

This commit is contained in:
Star 2024-10-26 22:12:41 +08:00
parent 6a20519361
commit b69e650d54
3 changed files with 17 additions and 11 deletions

View File

@ -17,6 +17,10 @@ var fileMD string
func init() { func init() {
obj := map[string]any{ obj := map[string]any{
"exists": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(1)
return vm.ToValue(u.FileExists(args.Path(0)))
},
"read": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { "read": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(1) args := gojs.MakeArgs(&argsIn, vm).Check(1)
if r, err := u.ReadFile(args.Path(0)); err == nil { if r, err := u.ReadFile(args.Path(0)); err == nil {

22
file.ts
View File

@ -1,6 +1,7 @@
// just for develop // just for develop
export default { export default {
exists,
read, read,
readBytes, readBytes,
write, write,
@ -13,16 +14,17 @@ export default {
cache cache
} }
function read(filename: string): string {return ''} function exists(filename: string): boolean { return false }
function readBytes(filename: string): any {return null} function read(filename: string): string { return '' }
function write(filename: string, data: any): void {} function readBytes(filename: string): any { return null }
function dir(filename: string): Array<FileInfo> {return null as any} function write(filename: string, data: any): void { }
function stat(filename: string): FileInfo {return null as any} function dir(filename: string): Array<FileInfo> { return null as any }
function find(filename: string): string {return ''} function stat(filename: string): FileInfo { return null as any }
function remove(filename: string): void {} function find(filename: string): string { return '' }
function rename(from: string, to: string): void {} function remove(filename: string): void { }
function copy(from: string, to: string): void {} function rename(from: string, to: string): void { }
function cache(filename: string, isCompress: boolean): void {} function copy(from: string, to: string): void { }
function cache(filename: string, isCompress: boolean): void { }
interface FileInfo { interface FileInfo {
name: string name: string

2
go.mod
View File

@ -3,7 +3,7 @@ module apigo.cc/gojs/file
go 1.18 go 1.18
require ( require (
apigo.cc/gojs v0.0.1 apigo.cc/gojs v0.0.3
github.com/ssgo/u v1.7.9 github.com/ssgo/u v1.7.9
) )