import { describe, expect, test } from '@jest/globals'; import JBase62 from "../src"; test('encode example 1', () => { const x = JBase62.getInstance("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") expect(x.encode({ A: 123 })).toEqual("6N4GIxiF9tHa12D") const xx = JBase62.getInstance("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") expect(xx.encode({ A: 123 })).toEqual("GXEQS7sPJ3RkBCN") }); test('encode example 2', () => { const x = JBase62.getInstance("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") expect(x.encode({ A: 123 })).toEqual("6N4GIxiF9tHa12D") // 是用最后一次的 characters const xx = JBase62.getInstance() // expect(xx.encode({ A: 123 })).toEqual("GXEQS7sPJ3RkBCN") expect(xx.encode({ A: 123 })).toEqual("6N4GIxiF9tHa12D") }); test('encode example 3', () => { const x = JBase62.getInstance("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") // set expect(x.set("6N4GIxiF9tHa12D", "a.b", 888)).toEqual("C2pN4cIiUNzT0X9EvQYWqK53E4r368y9hsb") // decode expect(x.decode("C2pN4cIiUNzT0X9EvQYWqK53E4r368y9hsb")).toEqual({ A: 123, a: { b: 888 } }) // get expect(x.get("C2pN4cIiUNzT0X9EvQYWqK53E4r368y9hsb", "a.b")).toEqual(888) // assign expect(x.assign("C2pN4cIiUNzT0X9EvQYWqK53E4r368y9hsb", { a: { c: 333 } })).toEqual("C2pN4cL9JKMyAdG8e5JWK3Z3cDQtawtYziX") expect(x.decode("C2pN4cL9JKMyAdG8e5JWK3Z3cDQtawtYziX")).toEqual({ A: 123, a: { c: 333 } }) // merge expect(x.assign("C2pN4cIiUNzT0X9EvQYWqK53E4r368y9hsb", { a: { c: 333 } }, true)).toEqual("Hd9OGloH4qT5y8F6q9rSqeLiTMwJLFdQbq7UrjP2I1ZmTSH") expect(x.decode("Hd9OGloH4qT5y8F6q9rSqeLiTMwJLFdQbq7UrjP2I1ZmTSH")).toEqual({ A: 123, a: { b: 888, c: 333 } }) });