@cosmjs/encoding
Advanced tools
Comparing version 0.26.5 to 0.27.0-rc1
@@ -6,17 +6,17 @@ "use strict"; | ||
it("encodes to ascii", () => { | ||
expect(ascii_1.toAscii("")).toEqual(new Uint8Array([])); | ||
expect(ascii_1.toAscii("abc")).toEqual(new Uint8Array([0x61, 0x62, 0x63])); | ||
expect(ascii_1.toAscii(" ?=-n|~+-*/\\")).toEqual(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c])); | ||
expect(() => ascii_1.toAscii("ö")).toThrow(); | ||
expect(() => ascii_1.toAscii("ß")).toThrow(); | ||
expect((0, ascii_1.toAscii)("")).toEqual(new Uint8Array([])); | ||
expect((0, ascii_1.toAscii)("abc")).toEqual(new Uint8Array([0x61, 0x62, 0x63])); | ||
expect((0, ascii_1.toAscii)(" ?=-n|~+-*/\\")).toEqual(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c])); | ||
expect(() => (0, ascii_1.toAscii)("ö")).toThrow(); | ||
expect(() => (0, ascii_1.toAscii)("ß")).toThrow(); | ||
}); | ||
it("decodes from ascii", () => { | ||
expect(ascii_1.fromAscii(new Uint8Array([]))).toEqual(""); | ||
expect(ascii_1.fromAscii(new Uint8Array([0x61, 0x62, 0x63]))).toEqual("abc"); | ||
expect(ascii_1.fromAscii(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c]))).toEqual(" ?=-n|~+-*/\\"); | ||
expect(() => ascii_1.fromAscii(new Uint8Array([0x00]))).toThrow(); | ||
expect(() => ascii_1.fromAscii(new Uint8Array([0x7f]))).toThrow(); | ||
expect(() => ascii_1.fromAscii(new Uint8Array([0xff]))).toThrow(); | ||
expect((0, ascii_1.fromAscii)(new Uint8Array([]))).toEqual(""); | ||
expect((0, ascii_1.fromAscii)(new Uint8Array([0x61, 0x62, 0x63]))).toEqual("abc"); | ||
expect((0, ascii_1.fromAscii)(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c]))).toEqual(" ?=-n|~+-*/\\"); | ||
expect(() => (0, ascii_1.fromAscii)(new Uint8Array([0x00]))).toThrow(); | ||
expect(() => (0, ascii_1.fromAscii)(new Uint8Array([0x7f]))).toThrow(); | ||
expect(() => (0, ascii_1.fromAscii)(new Uint8Array([0xff]))).toThrow(); | ||
}); | ||
}); | ||
//# sourceMappingURL=ascii.spec.js.map |
@@ -6,55 +6,55 @@ "use strict"; | ||
it("encodes to base64", () => { | ||
expect(base64_1.toBase64(new Uint8Array([]))).toEqual(""); | ||
expect(base64_1.toBase64(new Uint8Array([0x00]))).toEqual("AA=="); | ||
expect(base64_1.toBase64(new Uint8Array([0x00, 0x00]))).toEqual("AAA="); | ||
expect(base64_1.toBase64(new Uint8Array([0x00, 0x00, 0x00]))).toEqual("AAAA"); | ||
expect(base64_1.toBase64(new Uint8Array([0x00, 0x00, 0x00, 0x00]))).toEqual("AAAAAA=="); | ||
expect(base64_1.toBase64(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00]))).toEqual("AAAAAAA="); | ||
expect(base64_1.toBase64(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))).toEqual("AAAAAAAA"); | ||
expect(base64_1.toBase64(new Uint8Array([0x61]))).toEqual("YQ=="); | ||
expect(base64_1.toBase64(new Uint8Array([0x62]))).toEqual("Yg=="); | ||
expect(base64_1.toBase64(new Uint8Array([0x63]))).toEqual("Yw=="); | ||
expect(base64_1.toBase64(new Uint8Array([0x61, 0x62, 0x63]))).toEqual("YWJj"); | ||
expect((0, base64_1.toBase64)(new Uint8Array([]))).toEqual(""); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x00]))).toEqual("AA=="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x00, 0x00]))).toEqual("AAA="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x00, 0x00, 0x00]))).toEqual("AAAA"); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x00, 0x00, 0x00, 0x00]))).toEqual("AAAAAA=="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00]))).toEqual("AAAAAAA="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))).toEqual("AAAAAAAA"); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x61]))).toEqual("YQ=="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x62]))).toEqual("Yg=="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x63]))).toEqual("Yw=="); | ||
expect((0, base64_1.toBase64)(new Uint8Array([0x61, 0x62, 0x63]))).toEqual("YWJj"); | ||
}); | ||
it("decodes from base64", () => { | ||
expect(base64_1.fromBase64("")).toEqual(new Uint8Array([])); | ||
expect(base64_1.fromBase64("AA==")).toEqual(new Uint8Array([0x00])); | ||
expect(base64_1.fromBase64("AAA=")).toEqual(new Uint8Array([0x00, 0x00])); | ||
expect(base64_1.fromBase64("AAAA")).toEqual(new Uint8Array([0x00, 0x00, 0x00])); | ||
expect(base64_1.fromBase64("AAAAAA==")).toEqual(new Uint8Array([0x00, 0x00, 0x00, 0x00])); | ||
expect(base64_1.fromBase64("AAAAAAA=")).toEqual(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00])); | ||
expect(base64_1.fromBase64("AAAAAAAA")).toEqual(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | ||
expect(base64_1.fromBase64("YQ==")).toEqual(new Uint8Array([0x61])); | ||
expect(base64_1.fromBase64("Yg==")).toEqual(new Uint8Array([0x62])); | ||
expect(base64_1.fromBase64("Yw==")).toEqual(new Uint8Array([0x63])); | ||
expect(base64_1.fromBase64("YWJj")).toEqual(new Uint8Array([0x61, 0x62, 0x63])); | ||
expect((0, base64_1.fromBase64)("")).toEqual(new Uint8Array([])); | ||
expect((0, base64_1.fromBase64)("AA==")).toEqual(new Uint8Array([0x00])); | ||
expect((0, base64_1.fromBase64)("AAA=")).toEqual(new Uint8Array([0x00, 0x00])); | ||
expect((0, base64_1.fromBase64)("AAAA")).toEqual(new Uint8Array([0x00, 0x00, 0x00])); | ||
expect((0, base64_1.fromBase64)("AAAAAA==")).toEqual(new Uint8Array([0x00, 0x00, 0x00, 0x00])); | ||
expect((0, base64_1.fromBase64)("AAAAAAA=")).toEqual(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00])); | ||
expect((0, base64_1.fromBase64)("AAAAAAAA")).toEqual(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | ||
expect((0, base64_1.fromBase64)("YQ==")).toEqual(new Uint8Array([0x61])); | ||
expect((0, base64_1.fromBase64)("Yg==")).toEqual(new Uint8Array([0x62])); | ||
expect((0, base64_1.fromBase64)("Yw==")).toEqual(new Uint8Array([0x63])); | ||
expect((0, base64_1.fromBase64)("YWJj")).toEqual(new Uint8Array([0x61, 0x62, 0x63])); | ||
// invalid length | ||
expect(() => base64_1.fromBase64("a")).toThrow(); | ||
expect(() => base64_1.fromBase64("aa")).toThrow(); | ||
expect(() => base64_1.fromBase64("aaa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("a")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaa")).toThrow(); | ||
// proper length including invalid character | ||
expect(() => base64_1.fromBase64("aaa!")).toThrow(); | ||
expect(() => base64_1.fromBase64("aaa*")).toThrow(); | ||
expect(() => base64_1.fromBase64("aaaä")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaa!")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaa*")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaaä")).toThrow(); | ||
// proper length plus invalid character | ||
expect(() => base64_1.fromBase64("aaaa!")).toThrow(); | ||
expect(() => base64_1.fromBase64("aaaa*")).toThrow(); | ||
expect(() => base64_1.fromBase64("aaaaä")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaaa!")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaaa*")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaaaä")).toThrow(); | ||
// extra spaces | ||
expect(() => base64_1.fromBase64("aaaa ")).toThrow(); | ||
expect(() => base64_1.fromBase64(" aaaa")).toThrow(); | ||
expect(() => base64_1.fromBase64("aa aa")).toThrow(); | ||
expect(() => base64_1.fromBase64("aaaa\n")).toThrow(); | ||
expect(() => base64_1.fromBase64("\naaaa")).toThrow(); | ||
expect(() => base64_1.fromBase64("aa\naa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaaa ")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)(" aaaa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aa aa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aaaa\n")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("\naaaa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("aa\naa")).toThrow(); | ||
// position of = | ||
expect(() => base64_1.fromBase64("=aaa")).toThrow(); | ||
expect(() => base64_1.fromBase64("==aa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("=aaa")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("==aa")).toThrow(); | ||
// concatenated base64 strings should not be supported | ||
// see https://github.com/beatgammit/base64-js/issues/42 | ||
expect(() => base64_1.fromBase64("AAA=AAA=")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("AAA=AAA=")).toThrow(); | ||
// wrong number of = | ||
expect(() => base64_1.fromBase64("a===")).toThrow(); | ||
expect(() => (0, base64_1.fromBase64)("a===")).toThrow(); | ||
}); | ||
}); | ||
//# sourceMappingURL=base64.spec.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
// bech32 -e -h eth 9d4e856e572e442f0a4b2763e72d08a0e99d8ded | ||
const ethAddressRaw = hex_1.fromHex("9d4e856e572e442f0a4b2763e72d08a0e99d8ded"); | ||
const ethAddressRaw = (0, hex_1.fromHex)("9d4e856e572e442f0a4b2763e72d08a0e99d8ded"); | ||
describe("encode", () => { | ||
@@ -11,0 +11,0 @@ it("works", () => { |
@@ -7,21 +7,21 @@ "use strict"; | ||
// simple | ||
expect(hex_1.fromHex("")).toEqual(new Uint8Array([])); | ||
expect(hex_1.fromHex("00")).toEqual(new Uint8Array([0x00])); | ||
expect(hex_1.fromHex("01")).toEqual(new Uint8Array([0x01])); | ||
expect(hex_1.fromHex("10")).toEqual(new Uint8Array([0x10])); | ||
expect(hex_1.fromHex("11")).toEqual(new Uint8Array([0x11])); | ||
expect(hex_1.fromHex("112233")).toEqual(new Uint8Array([0x11, 0x22, 0x33])); | ||
expect(hex_1.fromHex("0123456789abcdef")).toEqual(new Uint8Array([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef])); | ||
expect((0, hex_1.fromHex)("")).toEqual(new Uint8Array([])); | ||
expect((0, hex_1.fromHex)("00")).toEqual(new Uint8Array([0x00])); | ||
expect((0, hex_1.fromHex)("01")).toEqual(new Uint8Array([0x01])); | ||
expect((0, hex_1.fromHex)("10")).toEqual(new Uint8Array([0x10])); | ||
expect((0, hex_1.fromHex)("11")).toEqual(new Uint8Array([0x11])); | ||
expect((0, hex_1.fromHex)("112233")).toEqual(new Uint8Array([0x11, 0x22, 0x33])); | ||
expect((0, hex_1.fromHex)("0123456789abcdef")).toEqual(new Uint8Array([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef])); | ||
// capital letters | ||
expect(hex_1.fromHex("AA")).toEqual(new Uint8Array([0xaa])); | ||
expect(hex_1.fromHex("aAbBcCdDeEfF")).toEqual(new Uint8Array([0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff])); | ||
expect((0, hex_1.fromHex)("AA")).toEqual(new Uint8Array([0xaa])); | ||
expect((0, hex_1.fromHex)("aAbBcCdDeEfF")).toEqual(new Uint8Array([0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff])); | ||
// error | ||
expect(() => hex_1.fromHex("a")).toThrow(); | ||
expect(() => hex_1.fromHex("aaa")).toThrow(); | ||
expect(() => hex_1.fromHex("a!")).toThrow(); | ||
expect(() => hex_1.fromHex("a ")).toThrow(); | ||
expect(() => hex_1.fromHex("aa ")).toThrow(); | ||
expect(() => hex_1.fromHex(" aa")).toThrow(); | ||
expect(() => hex_1.fromHex("a a")).toThrow(); | ||
expect(() => hex_1.fromHex("gg")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("a")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("aaa")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("a!")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("a ")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("aa ")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)(" aa")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("a a")).toThrow(); | ||
expect(() => (0, hex_1.fromHex)("gg")).toThrow(); | ||
}); | ||
@@ -31,11 +31,11 @@ }); | ||
it("works", () => { | ||
expect(hex_1.toHex(new Uint8Array([]))).toEqual(""); | ||
expect(hex_1.toHex(new Uint8Array([0x00]))).toEqual("00"); | ||
expect(hex_1.toHex(new Uint8Array([0x01]))).toEqual("01"); | ||
expect(hex_1.toHex(new Uint8Array([0x10]))).toEqual("10"); | ||
expect(hex_1.toHex(new Uint8Array([0x11]))).toEqual("11"); | ||
expect(hex_1.toHex(new Uint8Array([0x11, 0x22, 0x33]))).toEqual("112233"); | ||
expect(hex_1.toHex(new Uint8Array([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]))).toEqual("0123456789abcdef"); | ||
expect((0, hex_1.toHex)(new Uint8Array([]))).toEqual(""); | ||
expect((0, hex_1.toHex)(new Uint8Array([0x00]))).toEqual("00"); | ||
expect((0, hex_1.toHex)(new Uint8Array([0x01]))).toEqual("01"); | ||
expect((0, hex_1.toHex)(new Uint8Array([0x10]))).toEqual("10"); | ||
expect((0, hex_1.toHex)(new Uint8Array([0x11]))).toEqual("11"); | ||
expect((0, hex_1.toHex)(new Uint8Array([0x11, 0x22, 0x33]))).toEqual("112233"); | ||
expect((0, hex_1.toHex)(new Uint8Array([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]))).toEqual("0123456789abcdef"); | ||
}); | ||
}); | ||
//# sourceMappingURL=hex.spec.js.map |
@@ -7,46 +7,46 @@ "use strict"; | ||
// time zone +/- 0 | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+00:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-00:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+00:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-00:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
// time zone positive (full hours) | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+01:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 1, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+02:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 2, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+03:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 3, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+11:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 11, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+01:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 1, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+02:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 2, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+03:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 3, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+11:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 11, 12, 13))); | ||
// time zone negative (full hours) | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-01:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 1, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-02:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 2, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-03:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 3, 12, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-11:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 11, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-01:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 1, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-02:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 2, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-03:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 3, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-11:00")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 11, 12, 13))); | ||
// time zone positive (minutes only) | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+00:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 - 1, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+00:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 - 30, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+00:45")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 - 45, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+00:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 - 1, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+00:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 - 30, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+00:45")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 - 45, 13))); | ||
// time zone negative (minutes only) | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-00:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 + 1, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-00:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 + 30, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-00:45")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 + 45, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-00:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 + 1, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-00:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 + 30, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-00:45")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12 + 45, 13))); | ||
// time zone positive (hours and minutes) | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+01:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 1, 12 - 1, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+04:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 4, 12 - 30, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13+10:20")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 10, 12 - 20, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+01:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 1, 12 - 1, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+04:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 4, 12 - 30, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+10:20")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 - 10, 12 - 20, 13))); | ||
// time zone negative (hours and minutes) | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-01:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 1, 12 + 1, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-04:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 4, 12 + 30, 13))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13-10:20")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 10, 12 + 20, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-01:01")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 1, 12 + 1, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-04:30")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 4, 12 + 30, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13-10:20")).toEqual(new Date(Date.UTC(2002, 9, 2, 11 + 10, 12 + 20, 13))); | ||
}); | ||
it("parses dates with milliseconds", () => { | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.123Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.123Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
}); | ||
it("parses dates with low precision fractional seconds", () => { | ||
// 1 digit | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.0Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.1Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 100))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.9Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 900))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.0Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.1Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 100))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.9Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 900))); | ||
// 2 digit | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.00Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.12Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 120))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.99Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 990))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.00Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.12Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 120))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.99Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 990))); | ||
}); | ||
@@ -56,25 +56,25 @@ it("parses dates with high precision fractional seconds", () => { | ||
// 4 digits | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.0000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.1234Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.9999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.0000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.1234Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.9999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
// 5 digits | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.00000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.12345Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.99999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.00000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.12345Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.99999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
// 6 digits | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.123456Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.123456Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
// 7 digits | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.0000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.1234567Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.9999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.0000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.1234567Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.9999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
// 8 digits | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.00000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.12345678Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.99999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.00000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.12345678Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.99999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
// 9 digits | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.000000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.123456789Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect(rfc3339_1.fromRfc3339("2002-10-02T11:12:13.999999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.000000000Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 0))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.123456789Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 123))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13.999999999Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 999))); | ||
}); | ||
@@ -85,37 +85,37 @@ it("accepts space separators", () => { | ||
// to specify a full-date and full-time separated by (say) a space character. | ||
expect(rfc3339_1.fromRfc3339("2002-10-02 11:12:13Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
expect((0, rfc3339_1.fromRfc3339)("2002-10-02 11:12:13Z")).toEqual(new Date(Date.UTC(2002, 9, 2, 11, 12, 13))); | ||
}); | ||
it("throws for invalid format", () => { | ||
// extra whitespace | ||
expect(() => rfc3339_1.fromRfc3339(" 2002-10-02T11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12:13Z ")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12:13 Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)(" 2002-10-02T11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13Z ")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13 Z")).toThrow(); | ||
// wrong date separators | ||
expect(() => rfc3339_1.fromRfc3339("2002:10-02T11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10:02T11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002:10-02T11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10:02T11:12:13Z")).toThrow(); | ||
// wrong time separators | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11-12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12-13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11-12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12-13Z")).toThrow(); | ||
// wrong separator | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02TT11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02 T11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T 11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02t11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02x11:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02311:12:13Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02.11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02TT11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02 T11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T 11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02t11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02x11:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02311:12:13Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02.11:12:13Z")).toThrow(); | ||
// wrong time zone | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12:13")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12:13z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12:13 00:00")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2002-10-02T11:12:13+0000")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13 00:00")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2002-10-02T11:12:13+0000")).toThrow(); | ||
// wrong fractional seconds | ||
expect(() => rfc3339_1.fromRfc3339("2018-07-30T19:21:12345Z")).toThrow(); | ||
expect(() => rfc3339_1.fromRfc3339("2018-07-30T19:21:12.Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2018-07-30T19:21:12345Z")).toThrow(); | ||
expect(() => (0, rfc3339_1.fromRfc3339)("2018-07-30T19:21:12.Z")).toThrow(); | ||
}); | ||
it("encodes dates", () => { | ||
expect(rfc3339_1.toRfc3339(new Date(Date.UTC(0, 0, 1, 0, 0, 0)))).toEqual("1900-01-01T00:00:00.000Z"); | ||
expect(rfc3339_1.toRfc3339(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 456)))).toEqual("2002-10-02T11:12:13.456Z"); | ||
expect((0, rfc3339_1.toRfc3339)(new Date(Date.UTC(0, 0, 1, 0, 0, 0)))).toEqual("1900-01-01T00:00:00.000Z"); | ||
expect((0, rfc3339_1.toRfc3339)(new Date(Date.UTC(2002, 9, 2, 11, 12, 13, 456)))).toEqual("2002-10-02T11:12:13.456Z"); | ||
}); | ||
}); | ||
//# sourceMappingURL=rfc3339.spec.js.map |
@@ -6,48 +6,48 @@ "use strict"; | ||
it("encodes ascii strings", () => { | ||
expect(utf8_1.toUtf8("")).toEqual(new Uint8Array([])); | ||
expect(utf8_1.toUtf8("abc")).toEqual(new Uint8Array([0x61, 0x62, 0x63])); | ||
expect(utf8_1.toUtf8(" ?=-n|~+-*/\\")).toEqual(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c])); | ||
expect((0, utf8_1.toUtf8)("")).toEqual(new Uint8Array([])); | ||
expect((0, utf8_1.toUtf8)("abc")).toEqual(new Uint8Array([0x61, 0x62, 0x63])); | ||
expect((0, utf8_1.toUtf8)(" ?=-n|~+-*/\\")).toEqual(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c])); | ||
}); | ||
it("decodes ascii string", () => { | ||
expect(utf8_1.fromUtf8(new Uint8Array([]))).toEqual(""); | ||
expect(utf8_1.fromUtf8(new Uint8Array([0x61, 0x62, 0x63]))).toEqual("abc"); | ||
expect(utf8_1.fromUtf8(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c]))).toEqual(" ?=-n|~+-*/\\"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([]))).toEqual(""); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0x61, 0x62, 0x63]))).toEqual("abc"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0x20, 0x3f, 0x3d, 0x2d, 0x6e, 0x7c, 0x7e, 0x2b, 0x2d, 0x2a, 0x2f, 0x5c]))).toEqual(" ?=-n|~+-*/\\"); | ||
}); | ||
it("encodes null character", () => { | ||
expect(utf8_1.toUtf8("\u0000")).toEqual(new Uint8Array([0x00])); | ||
expect((0, utf8_1.toUtf8)("\u0000")).toEqual(new Uint8Array([0x00])); | ||
}); | ||
it("decodes null byte", () => { | ||
expect(utf8_1.fromUtf8(new Uint8Array([0x00]))).toEqual("\u0000"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0x00]))).toEqual("\u0000"); | ||
}); | ||
it("encodes Basic Multilingual Plane strings", () => { | ||
expect(utf8_1.toUtf8("ö")).toEqual(new Uint8Array([0xc3, 0xb6])); | ||
expect(utf8_1.toUtf8("¥")).toEqual(new Uint8Array([0xc2, 0xa5])); | ||
expect(utf8_1.toUtf8("Ф")).toEqual(new Uint8Array([0xd0, 0xa4])); | ||
expect(utf8_1.toUtf8("ⱴ")).toEqual(new Uint8Array([0xe2, 0xb1, 0xb4])); | ||
expect(utf8_1.toUtf8("ⵘ")).toEqual(new Uint8Array([0xe2, 0xb5, 0x98])); | ||
expect((0, utf8_1.toUtf8)("ö")).toEqual(new Uint8Array([0xc3, 0xb6])); | ||
expect((0, utf8_1.toUtf8)("¥")).toEqual(new Uint8Array([0xc2, 0xa5])); | ||
expect((0, utf8_1.toUtf8)("Ф")).toEqual(new Uint8Array([0xd0, 0xa4])); | ||
expect((0, utf8_1.toUtf8)("ⱴ")).toEqual(new Uint8Array([0xe2, 0xb1, 0xb4])); | ||
expect((0, utf8_1.toUtf8)("ⵘ")).toEqual(new Uint8Array([0xe2, 0xb5, 0x98])); | ||
}); | ||
it("decodes Basic Multilingual Plane strings", () => { | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xc3, 0xb6]))).toEqual("ö"); | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xc2, 0xa5]))).toEqual("¥"); | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xd0, 0xa4]))).toEqual("Ф"); | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xe2, 0xb1, 0xb4]))).toEqual("ⱴ"); | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xe2, 0xb5, 0x98]))).toEqual("ⵘ"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xc3, 0xb6]))).toEqual("ö"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xc2, 0xa5]))).toEqual("¥"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xd0, 0xa4]))).toEqual("Ф"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xe2, 0xb1, 0xb4]))).toEqual("ⱴ"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xe2, 0xb5, 0x98]))).toEqual("ⵘ"); | ||
}); | ||
it("encodes Supplementary Multilingual Plane strings", () => { | ||
// U+1F0A1 | ||
expect(utf8_1.toUtf8("🂡")).toEqual(new Uint8Array([0xf0, 0x9f, 0x82, 0xa1])); | ||
expect((0, utf8_1.toUtf8)("🂡")).toEqual(new Uint8Array([0xf0, 0x9f, 0x82, 0xa1])); | ||
// U+1034A | ||
expect(utf8_1.toUtf8("𐍊")).toEqual(new Uint8Array([0xf0, 0x90, 0x8d, 0x8a])); | ||
expect((0, utf8_1.toUtf8)("𐍊")).toEqual(new Uint8Array([0xf0, 0x90, 0x8d, 0x8a])); | ||
}); | ||
it("decodes Supplementary Multilingual Plane strings", () => { | ||
// U+1F0A1 | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xf0, 0x9f, 0x82, 0xa1]))).toEqual("🂡"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xf0, 0x9f, 0x82, 0xa1]))).toEqual("🂡"); | ||
// U+1034A | ||
expect(utf8_1.fromUtf8(new Uint8Array([0xf0, 0x90, 0x8d, 0x8a]))).toEqual("𐍊"); | ||
expect((0, utf8_1.fromUtf8)(new Uint8Array([0xf0, 0x90, 0x8d, 0x8a]))).toEqual("𐍊"); | ||
}); | ||
it("throws on invalid utf8 bytes", () => { | ||
// Broken UTF8 example from https://github.com/nodejs/node/issues/16894 | ||
expect(() => utf8_1.fromUtf8(new Uint8Array([0xf0, 0x80, 0x80]))).toThrow(); | ||
expect(() => (0, utf8_1.fromUtf8)(new Uint8Array([0xf0, 0x80, 0x80]))).toThrow(); | ||
}); | ||
}); | ||
//# sourceMappingURL=utf8.spec.js.map |
{ | ||
"name": "@cosmjs/encoding", | ||
"version": "0.26.5", | ||
"version": "0.27.0-rc1", | ||
"description": "Encoding helpers for blockchain projects", | ||
@@ -31,3 +31,3 @@ "contributors": [ | ||
"format-text": "prettier --write \"./*.md\"", | ||
"test-node": "node --require esm jasmine-testrunner.js", | ||
"test-node": "yarn node jasmine-testrunner.js", | ||
"test-edge": "yarn pack-web && karma start --single-run --browsers Edge", | ||
@@ -80,7 +80,8 @@ "test-firefox": "yarn pack-web && karma start --single-run --browsers Firefox", | ||
"ts-node": "^8", | ||
"typedoc": "^0.21", | ||
"typescript": "~4.3", | ||
"typedoc": "^0.22", | ||
"typescript": "~4.4", | ||
"webpack": "^5.32.0", | ||
"webpack-cli": "^4.6.0" | ||
} | ||
}, | ||
"stableVersion": "0.26.5" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71788