@bare-ts/lib 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +12 -2
  2. package/dist/codec/data.d.ts +4 -4
  3. package/dist/codec/data.js +26 -0
  4. package/dist/codec/float-array.d.ts +12 -12
  5. package/dist/codec/float-array.js +85 -0
  6. package/dist/codec/i16-array.d.ts +6 -6
  7. package/dist/codec/i16-array.js +43 -0
  8. package/dist/codec/i32-array.d.ts +6 -6
  9. package/dist/codec/i32-array.js +43 -0
  10. package/dist/codec/i64-array.d.ts +6 -6
  11. package/dist/codec/i64-array.js +43 -0
  12. package/dist/codec/i8-array.d.ts +4 -4
  13. package/dist/codec/i8-array.js +24 -0
  14. package/dist/codec/index.js +15 -0
  15. package/dist/codec/primitive.d.ts +34 -36
  16. package/dist/codec/primitive.js +345 -0
  17. package/dist/codec/string.d.ts +4 -2
  18. package/dist/codec/string.js +126 -0
  19. package/dist/codec/u16-array.d.ts +6 -6
  20. package/dist/codec/u16-array.js +43 -0
  21. package/dist/codec/u32-array.d.ts +6 -6
  22. package/dist/codec/u32-array.js +43 -0
  23. package/dist/codec/u64-array.d.ts +6 -6
  24. package/dist/codec/u64-array.js +43 -0
  25. package/dist/codec/u8-array.d.ts +4 -4
  26. package/dist/codec/u8-array.js +27 -0
  27. package/dist/codec/u8-clamped-array.d.ts +4 -4
  28. package/dist/codec/u8-clamped-array.js +24 -0
  29. package/dist/core/bare-error.js +14 -0
  30. package/dist/core/byte-cursor.d.ts +26 -8
  31. package/dist/core/byte-cursor.js +42 -0
  32. package/dist/core/config.d.ts +6 -1
  33. package/dist/core/config.js +27 -0
  34. package/dist/core/index.js +5 -0
  35. package/dist/index.cjs +591 -636
  36. package/dist/index.js +3 -987
  37. package/dist/util/assert.d.ts +6 -1
  38. package/dist/util/assert.js +1 -4
  39. package/dist/util/constants.d.ts +13 -0
  40. package/dist/util/constants.js +30 -0
  41. package/dist/util/util.js +6 -0
  42. package/dist/util/validator.js +40 -0
  43. package/package.json +16 -14
  44. package/CHANGELOG.md +0 -12
@@ -2,4 +2,9 @@ export declare class AssertionError extends Error {
2
2
  readonly name: "AssertionError";
3
3
  constructor(message: string);
4
4
  }
5
- export default function assert(test: boolean, message: Error | string): asserts test;
5
+ export declare function assert(test: boolean, message: string): asserts test;
6
+ declare const Error: V8ErrorConstructor;
7
+ interface V8ErrorConstructor extends ErrorConstructor {
8
+ readonly captureStackTrace?: (e: Error, f: unknown) => void;
9
+ }
10
+ export {};
@@ -7,9 +7,6 @@ var AssertionError = class extends Error {
7
7
  };
8
8
  function assert(test, message) {
9
9
  if (!test) {
10
- if (message instanceof Error) {
11
- throw message;
12
- }
13
10
  const e = new AssertionError(message);
14
11
  if (Error.captureStackTrace) {
15
12
  Error.captureStackTrace(e, assert);
@@ -19,6 +16,6 @@ function assert(test, message) {
19
16
  }
20
17
  export {
21
18
  AssertionError,
22
- assert as default
19
+ assert
23
20
  };
24
21
  //# sourceMappingURL=assert.js.map
@@ -0,0 +1,13 @@
1
+ export declare const I16_BYTE_COUNT = 2;
2
+ export declare const I32_BYTE_COUNT = 4;
3
+ export declare const I64_BYTE_COUNT = 8;
4
+ export declare const U16_BYTE_COUNT = 2;
5
+ export declare const U32_BYTE_COUNT = 4;
6
+ export declare const U64_BYTE_COUNT = 8;
7
+ export declare const INT_SAFE_MAX_BYTE_COUNT = 8;
8
+ export declare const UINT_MAX_BYTE_COUNT = 10;
9
+ export declare const UINT_SAFE_MAX_BYTE_COUNT = 8;
10
+ export declare const INVALID_UTF8_STRING = "invalid UTF-8 string";
11
+ export declare const NON_CANONICAL_REPRESENTATION = "must be canonical";
12
+ export declare const TOO_LARGE_BUFFER = "too large buffer";
13
+ export declare const TOO_LARGE_NUMBER = "too large number";
@@ -0,0 +1,30 @@
1
+ // src/util/constants.ts
2
+ var I16_BYTE_COUNT = 2;
3
+ var I32_BYTE_COUNT = 4;
4
+ var I64_BYTE_COUNT = 8;
5
+ var U16_BYTE_COUNT = 2;
6
+ var U32_BYTE_COUNT = 4;
7
+ var U64_BYTE_COUNT = 8;
8
+ var INT_SAFE_MAX_BYTE_COUNT = 8;
9
+ var UINT_MAX_BYTE_COUNT = 10;
10
+ var UINT_SAFE_MAX_BYTE_COUNT = 8;
11
+ var INVALID_UTF8_STRING = "invalid UTF-8 string";
12
+ var NON_CANONICAL_REPRESENTATION = "must be canonical";
13
+ var TOO_LARGE_BUFFER = "too large buffer";
14
+ var TOO_LARGE_NUMBER = "too large number";
15
+ export {
16
+ I16_BYTE_COUNT,
17
+ I32_BYTE_COUNT,
18
+ I64_BYTE_COUNT,
19
+ INT_SAFE_MAX_BYTE_COUNT,
20
+ INVALID_UTF8_STRING,
21
+ NON_CANONICAL_REPRESENTATION,
22
+ TOO_LARGE_BUFFER,
23
+ TOO_LARGE_NUMBER,
24
+ U16_BYTE_COUNT,
25
+ U32_BYTE_COUNT,
26
+ U64_BYTE_COUNT,
27
+ UINT_MAX_BYTE_COUNT,
28
+ UINT_SAFE_MAX_BYTE_COUNT
29
+ };
30
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,6 @@
1
+ // src/util/util.ts
2
+ var IS_LITTLE_ENDIAN_PLATFORM = /* @__PURE__ */ new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1;
3
+ export {
4
+ IS_LITTLE_ENDIAN_PLATFORM
5
+ };
6
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1,40 @@
1
+ // src/util/validator.ts
2
+ function isI8(val) {
3
+ return val === val << 24 >> 24;
4
+ }
5
+ function isI16(val) {
6
+ return val === val << 16 >> 16;
7
+ }
8
+ function isI32(val) {
9
+ return val === (val | 0);
10
+ }
11
+ function isI64(val) {
12
+ return val === BigInt.asIntN(64, val);
13
+ }
14
+ function isSafeU64(val) {
15
+ return Number.isSafeInteger(val) && val >= 0;
16
+ }
17
+ function isU8(val) {
18
+ return val === (val & 255);
19
+ }
20
+ function isU16(val) {
21
+ return val === (val & 65535);
22
+ }
23
+ function isU32(val) {
24
+ return val === val >>> 0;
25
+ }
26
+ function isU64(val) {
27
+ return val === BigInt.asUintN(64, val);
28
+ }
29
+ export {
30
+ isI16,
31
+ isI32,
32
+ isI64,
33
+ isI8,
34
+ isSafeU64,
35
+ isU16,
36
+ isU32,
37
+ isU64,
38
+ isU8
39
+ };
40
+ //# sourceMappingURL=validator.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bare-ts/lib",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript library for BARE, a compact and simple binary-serialization format",
5
5
  "keywords": [
6
6
  "bare",
@@ -15,7 +15,7 @@
15
15
  "homepage": "https://baremessages.org",
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/bare-ts/lib"
18
+ "url": "git+https://github.com/bare-ts/lib.git"
19
19
  },
20
20
  "bugs": {
21
21
  "url": "https://github.com/bare-ts/lib/issues"
@@ -28,26 +28,29 @@
28
28
  "module": "./dist/index.js",
29
29
  "es2015": "./dist/index.js",
30
30
  "types": "./dist/index.d.ts",
31
- "browser": {
32
- "assert": "./dist/util/assert.js"
33
- },
34
31
  "exports": {
35
- "import": "./dist/index.js",
36
- "require": "./dist/index.cjs"
32
+ "require": "./dist/index.cjs",
33
+ "default": "./dist/index.js"
37
34
  },
38
35
  "sideEffects": false,
39
36
  "files": [
40
37
  "dist/*.cjs",
41
38
  "dist/*.d.ts",
42
39
  "dist/*.js",
40
+ "dist/**/*.cjs",
43
41
  "dist/**/*.d.ts",
44
42
  "dist/**/*.js"
45
43
  ],
44
+ "directories": {
45
+ "test": "tests"
46
+ },
46
47
  "scripts": {
47
- "build": "tsc -b src && node ./scripts/build.js",
48
+ "build": "sh ./scripts/build.sh",
48
49
  "clean": "rm -rf dist coverage",
49
- "prepublishOnly": "npm run clean && npm run test",
50
- "test": "npm run build && tsc -b tests && oletus tests/**/*.test.js"
50
+ "prepare": "validate-commit-msg",
51
+ "prepublishOnly": "npm run clean && npm test",
52
+ "test": "npm run build && tsc -b tests && oletus tests/**/*.test.js",
53
+ "test:coverage": "c8 --reporter=lcovonly npm test"
51
54
  },
52
55
  "size-limit": [
53
56
  {
@@ -56,11 +59,10 @@
56
59
  }
57
60
  ],
58
61
  "devDependencies": {
59
- "@types/node": "^17.0.6",
60
- "esbuild": "^0.14.10",
62
+ "esbuild": "~0.14.10",
61
63
  "oletus": "^3.2.0",
62
- "prettier": "^2.5.1",
63
- "typescript": "^4.5.4",
64
+ "prettier": "~2.5.1",
65
+ "typescript": "~4.5.4",
64
66
  "validate-commit-message": "^3.2.0"
65
67
  }
66
68
  }
package/CHANGELOG.md DELETED
@@ -1,12 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.1.0 (2022-01-02)
4
-
5
- * `ByteCursor` abstraction to read and write safely a buffer of bytes
6
-
7
- * Enable to configure at runtime:
8
- - initial buffer length
9
- - maximum buffer length
10
- - thresholds (string length) for switching from custom to native UTF-8 decoders/encoders
11
-
12
- * Decoders and encoders for basic types (bool, opaque data, floats, integers, typed arrays, UTF-8 string)