From b69e650d549b5e66b3b0ae92d952ebdd9939e2ba Mon Sep 17 00:00:00 2001 From: Star Date: Sat, 26 Oct 2024 22:12:41 +0800 Subject: [PATCH] add exists --- file.go | 4 ++++ file.ts | 22 ++++++++++++---------- go.mod | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/file.go b/file.go index da17764..925ad93 100644 --- a/file.go +++ b/file.go @@ -17,6 +17,10 @@ var fileMD string func init() { 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 { args := gojs.MakeArgs(&argsIn, vm).Check(1) if r, err := u.ReadFile(args.Path(0)); err == nil { diff --git a/file.ts b/file.ts index 0230e98..33acf4a 100644 --- a/file.ts +++ b/file.ts @@ -1,6 +1,7 @@ // just for develop export default { + exists, read, readBytes, write, @@ -13,16 +14,17 @@ export default { cache } -function read(filename: string): string {return ''} -function readBytes(filename: string): any {return null} -function write(filename: string, data: any): void {} -function dir(filename: string): Array {return null as any} -function stat(filename: string): FileInfo {return null as any} -function find(filename: string): string {return ''} -function remove(filename: string): void {} -function rename(from: string, to: string): void {} -function copy(from: string, to: string): void {} -function cache(filename: string, isCompress: boolean): void {} +function exists(filename: string): boolean { return false } +function read(filename: string): string { return '' } +function readBytes(filename: string): any { return null } +function write(filename: string, data: any): void { } +function dir(filename: string): Array { return null as any } +function stat(filename: string): FileInfo { return null as any } +function find(filename: string): string { return '' } +function remove(filename: string): void { } +function rename(from: string, to: string): void { } +function copy(from: string, to: string): void { } +function cache(filename: string, isCompress: boolean): void { } interface FileInfo { name: string diff --git a/go.mod b/go.mod index 7ccde64..5bd7117 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module apigo.cc/gojs/file go 1.18 require ( - apigo.cc/gojs v0.0.1 + apigo.cc/gojs v0.0.3 github.com/ssgo/u v1.7.9 )