Compare commits
No commits in common. "master" and "v0.0.12" have entirely different histories.
6
go.mod
6
go.mod
@ -1,9 +1,9 @@
|
|||||||
module apigo.cc/gojs/util
|
module apigo.cc/gojs/util
|
||||||
|
|
||||||
go 1.24
|
go 1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
apigo.cc/gojs v0.0.25
|
apigo.cc/gojs v0.0.21
|
||||||
apigo.cc/gojs/console v0.0.2
|
apigo.cc/gojs/console v0.0.2
|
||||||
github.com/ZZMarquis/gm v1.3.2
|
github.com/ZZMarquis/gm v1.3.2
|
||||||
github.com/emmansun/gmsm v0.30.1
|
github.com/emmansun/gmsm v0.30.1
|
||||||
@ -18,7 +18,7 @@ require (
|
|||||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||||
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
|
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
|
||||||
github.com/ssgo/config v1.7.9 // indirect
|
github.com/ssgo/config v1.7.9 // indirect
|
||||||
github.com/ssgo/log v1.7.9 // indirect
|
github.com/ssgo/log v1.7.7 // indirect
|
||||||
github.com/ssgo/standard v1.7.7 // indirect
|
github.com/ssgo/standard v1.7.7 // indirect
|
||||||
github.com/ssgo/tool v0.4.29 // indirect
|
github.com/ssgo/tool v0.4.29 // indirect
|
||||||
golang.org/x/crypto v0.40.0 // indirect
|
golang.org/x/crypto v0.40.0 // indirect
|
||||||
|
4
util.go
4
util.go
@ -838,10 +838,6 @@ func init() {
|
|||||||
TsCode: utilTS,
|
TsCode: utilTS,
|
||||||
Example: utilMD,
|
Example: utilMD,
|
||||||
JsCode: `
|
JsCode: `
|
||||||
$MOD$.parseDate = function (v) {
|
|
||||||
return new Date($MOD$.timestampMS(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
$MOD$.keysBy = function (obj, ...fieldAndValues) {
|
$MOD$.keysBy = function (obj, ...fieldAndValues) {
|
||||||
let keys = []
|
let keys = []
|
||||||
for (let k in obj) {
|
for (let k in obj) {
|
||||||
|
18
util.ts
18
util.ts
@ -59,12 +59,12 @@ export default {
|
|||||||
hmacSM3,
|
hmacSM3,
|
||||||
tpl,
|
tpl,
|
||||||
formatDate,
|
formatDate,
|
||||||
addDate,
|
|
||||||
timestampMS,
|
timestampMS,
|
||||||
timestamp,
|
timestamp,
|
||||||
toDatetime,
|
toDatetime,
|
||||||
|
fromDatetime,
|
||||||
toDate,
|
toDate,
|
||||||
parseDate,
|
fromDate,
|
||||||
joinPath,
|
joinPath,
|
||||||
getPathDir,
|
getPathDir,
|
||||||
getPathBase,
|
getPathBase,
|
||||||
@ -163,13 +163,13 @@ function hmacSHA256(key: any, ...data: any[]): any { return '' }
|
|||||||
function hmacSHA512(key: any, ...data: any[]): any { return '' }
|
function hmacSHA512(key: any, ...data: any[]): any { return '' }
|
||||||
function hmacSM3(key: any, ...data: any[]): any { return '' }
|
function hmacSM3(key: any, ...data: any[]): any { return '' }
|
||||||
function tpl(text: string, data: any, functions?: Object): string { return '' }
|
function tpl(text: string, data: any, functions?: Object): string { return '' }
|
||||||
function formatDate(format: string, value?: any): string { return '' }
|
function formatDate(format: string, timestamp?: number): string { return '' }
|
||||||
function addDate(add: string, value?: any): string { return '' }
|
function timestampMS(): number { return 0 }
|
||||||
function timestampMS(value?: any): number { return 0 }
|
function timestamp(): number { return 0 }
|
||||||
function timestamp(value?: any): number { return 0 }
|
function toDatetime(timestamp?: number): string { return '' }
|
||||||
function toDatetime(value?: any): string { return '' }
|
function fromDatetime(datetimeStr: string): number { return 0 }
|
||||||
function toDate(value?: any): string { return '' }
|
function toDate(timestamp?: number): string { return '' }
|
||||||
function parseDate(value: any): Date { return new Date() }
|
function fromDate(dateStr: string): number { return 0 }
|
||||||
function joinPath(...paths: string[]): string { return '' }
|
function joinPath(...paths: string[]): string { return '' }
|
||||||
function getPathDir(path: string): string { return '' }
|
function getPathDir(path: string): string { return '' }
|
||||||
function getPathBase(path: string): string { return '' }
|
function getPathBase(path: string): string { return '' }
|
||||||
|
14
util_test.go
14
util_test.go
@ -37,6 +37,10 @@ func TestHash(t *testing.T) {
|
|||||||
sm4R, _ := vm.RunCode("util.hex(util.sm4('hello 123','12345678901234567','12345678901234567'))")
|
sm4R, _ := vm.RunCode("util.hex(util.sm4('hello 123','12345678901234567','12345678901234567'))")
|
||||||
testIsSame(vm, t, "util.unSM4('"+u.String(sm4R)+"','12345678901234567','12345678901234567')", "hello 123")
|
testIsSame(vm, t, "util.unSM4('"+u.String(sm4R)+"','12345678901234567','12345678901234567')", "hello 123")
|
||||||
testIsSame(vm, t, "util.gzip('hello 123')", u.GzipN([]byte("hello 123")))
|
testIsSame(vm, t, "util.gzip('hello 123')", u.GzipN([]byte("hello 123")))
|
||||||
|
tm, _ := time.ParseInLocation("2006-01-02 15:04:05", "2024-01-01 00:00:00", time.Local)
|
||||||
|
testIsSame(vm, t, "util.timestampMS('2024-01-01 00:00:00')", tm.UnixMilli())
|
||||||
|
testIsSame(vm, t, "util.timestampMS('Mon Jan 01 2024 00:00:00 GMT+0800 (中国标准时间)')", tm.UnixMilli())
|
||||||
|
testIsSame(vm, t, "util.timestampMS(new Date("+u.String(tm.UnixMilli())+"))", tm.UnixMilli())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestECDSA(t *testing.T) {
|
func TestECDSA(t *testing.T) {
|
||||||
@ -123,16 +127,6 @@ func TestRSA(t *testing.T) {
|
|||||||
fmt.Println(u.Green("ecdsa test passed"))
|
fmt.Println(u.Green("ecdsa test passed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDate(t *testing.T) {
|
|
||||||
vm := gojs.New()
|
|
||||||
vm.RunCode("import util from 'apigo.cc/gojs/util'\nimport co from 'apigo.cc/gojs/console'")
|
|
||||||
tm, _ := time.ParseInLocation("2006-01-02 15:04:05", "2024-01-01 00:00:00", time.Local)
|
|
||||||
testIsSame(vm, t, "util.timestampMS('2024-01-01 00:00:00')", tm.UnixMilli())
|
|
||||||
testIsSame(vm, t, "util.timestampMS('Mon Jan 01 2024 00:00:00 GMT+0800 (中国标准时间)')", tm.UnixMilli())
|
|
||||||
testIsSame(vm, t, "util.timestampMS(new Date("+u.String(tm.UnixMilli())+"))", tm.UnixMilli())
|
|
||||||
testIsSame(vm, t, "util.parseDate(new Date('Mon Jan 01 2024 00:00:00 GMT+0800 (中国标准时间)')).getTime()", tm.UnixMilli())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testIsSame(vm *gojs.Runtime, t *testing.T, code string, checkValue any) {
|
func testIsSame(vm *gojs.Runtime, t *testing.T, code string, checkValue any) {
|
||||||
r, err := vm.RunCode(code)
|
r, err := vm.RunCode(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user