@smithy/util-body-length-browser 2.0.0 → 2.1.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.
@@ -1,26 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateBodyLength = void 0;
4
- const calculateBodyLength = (body) => {
5
- if (typeof body === "string") {
6
- let len = body.length;
7
- for (let i = len - 1; i >= 0; i--) {
8
- const code = body.charCodeAt(i);
9
- if (code > 0x7f && code <= 0x7ff)
10
- len++;
11
- else if (code > 0x7ff && code <= 0xffff)
12
- len += 2;
13
- if (code >= 0xdc00 && code <= 0xdfff)
14
- i--;
15
- }
16
- return len;
17
- }
18
- else if (typeof body.byteLength === "number") {
19
- return body.byteLength;
20
- }
21
- else if (typeof body.size === "number") {
22
- return body.size;
23
- }
24
- throw new Error(`Body Length computation failed for ${body}`);
25
- };
26
- exports.calculateBodyLength = calculateBodyLength;
1
+ module.exports = require("./index.js");
package/dist-cjs/index.js CHANGED
@@ -1,4 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./calculateBodyLength"), exports);
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ calculateBodyLength: () => calculateBodyLength
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/calculateBodyLength.ts
28
+ var TEXT_ENCODER = typeof TextEncoder == "function" ? new TextEncoder() : null;
29
+ var calculateBodyLength = /* @__PURE__ */ __name((body) => {
30
+ if (typeof body === "string") {
31
+ if (TEXT_ENCODER) {
32
+ return TEXT_ENCODER.encode(body).byteLength;
33
+ }
34
+ let len = body.length;
35
+ for (let i = len - 1; i >= 0; i--) {
36
+ const code = body.charCodeAt(i);
37
+ if (code > 127 && code <= 2047)
38
+ len++;
39
+ else if (code > 2047 && code <= 65535)
40
+ len += 2;
41
+ if (code >= 56320 && code <= 57343)
42
+ i--;
43
+ }
44
+ return len;
45
+ } else if (typeof body.byteLength === "number") {
46
+ return body.byteLength;
47
+ } else if (typeof body.size === "number") {
48
+ return body.size;
49
+ }
50
+ throw new Error(`Body Length computation failed for ${body}`);
51
+ }, "calculateBodyLength");
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ calculateBodyLength
55
+ });
@@ -1,5 +1,9 @@
1
+ const TEXT_ENCODER = typeof TextEncoder == "function" ? new TextEncoder() : null;
1
2
  export const calculateBodyLength = (body) => {
2
3
  if (typeof body === "string") {
4
+ if (TEXT_ENCODER) {
5
+ return TEXT_ENCODER.encode(body).byteLength;
6
+ }
3
7
  let len = body.length;
4
8
  for (let i = len - 1; i >= 0; i--) {
5
9
  const code = body.charCodeAt(i);
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@smithy/util-body-length-browser",
3
3
  "description": "Determines the length of a request body in browsers",
4
- "version": "2.0.0",
4
+ "version": "2.1.0",
5
5
  "scripts": {
6
6
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
7
- "build:cjs": "tsc -p tsconfig.cjs.json",
8
- "build:es": "tsc -p tsconfig.es.json",
9
- "build:types": "tsc -p tsconfig.types.json",
7
+ "build:cjs": "node ../../scripts/inline util-body-length-browser",
8
+ "build:es": "yarn g:tsc -p tsconfig.es.json",
9
+ "build:types": "yarn g:tsc -p tsconfig.types.json",
10
10
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
11
11
  "stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
12
- "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12
+ "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
13
13
  "lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
14
14
  "format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
15
- "test": "jest"
15
+ "test": "yarn g:jest"
16
16
  },
17
17
  "main": "./dist-cjs/index.js",
18
18
  "module": "./dist-es/index.js",
@@ -45,10 +45,8 @@
45
45
  "@tsconfig/recommended": "1.0.1",
46
46
  "concurrently": "7.0.0",
47
47
  "downlevel-dts": "0.10.1",
48
- "jest": "28.1.1",
49
48
  "rimraf": "3.0.2",
50
- "typedoc": "0.23.23",
51
- "typescript": "~4.9.5"
49
+ "typedoc": "0.23.23"
52
50
  },
53
51
  "typedoc": {
54
52
  "entryPoint": "src/index.ts"