@smithy/util-body-length-browser 4.2.1 → 4.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.
- package/dist-cjs/index.js +5 -30
- package/dist-es/index.js +1 -1
- package/dist-types/index.d.ts +2 -4
- package/package.json +5 -25
- package/README.md +0 -12
- package/dist-es/calculateBodyLength.js +0 -26
- package/dist-types/calculateBodyLength.d.ts +0 -4
- package/dist-types/ts3.4/calculateBodyLength.d.ts +0 -4
- package/dist-types/ts3.4/index.d.ts +0 -4
package/dist-cjs/index.js
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (TEXT_ENCODER) {
|
|
7
|
-
return TEXT_ENCODER.encode(body).byteLength;
|
|
8
|
-
}
|
|
9
|
-
let len = body.length;
|
|
10
|
-
for (let i = len - 1; i >= 0; i--) {
|
|
11
|
-
const code = body.charCodeAt(i);
|
|
12
|
-
if (code > 0x7f && code <= 0x7ff)
|
|
13
|
-
len++;
|
|
14
|
-
else if (code > 0x7ff && code <= 0xffff)
|
|
15
|
-
len += 2;
|
|
16
|
-
if (code >= 0xdc00 && code <= 0xdfff)
|
|
17
|
-
i--;
|
|
18
|
-
}
|
|
19
|
-
return len;
|
|
20
|
-
}
|
|
21
|
-
else if (typeof body.byteLength === "number") {
|
|
22
|
-
return body.byteLength;
|
|
23
|
-
}
|
|
24
|
-
else if (typeof body.size === "number") {
|
|
25
|
-
return body.size;
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`Body Length computation failed for ${body}`);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
exports.calculateBodyLength = calculateBodyLength;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateBodyLength = void 0;
|
|
4
|
+
var serde_1 = require("@smithy/core/serde");
|
|
5
|
+
Object.defineProperty(exports, "calculateBodyLength", { enumerable: true, get: function () { return serde_1.calculateBodyLength; } });
|
package/dist-es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { calculateBodyLength } from "@smithy/core/serde";
|
package/dist-types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/util-body-length-browser",
|
|
3
3
|
"description": "Determines the length of a request body in browsers",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.3.0",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"build:types": "yarn g:tsc -p tsconfig.types.json",
|
|
10
|
-
"build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
|
|
11
|
-
"stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
|
|
12
|
-
"clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
|
|
13
|
-
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
|
|
14
|
-
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
|
|
15
|
-
"test": "yarn g:vitest run",
|
|
16
|
-
"test:watch": "yarn g:vitest watch"
|
|
6
|
+
"build": "yarn g:tsc -p tsconfig.cjs.json && yarn g:tsc -p tsconfig.es.json && yarn g:tsc -p tsconfig.types.json",
|
|
7
|
+
"clean": "rm -rf dist-cjs dist-es dist-types",
|
|
8
|
+
"stage-release": "rm -rf .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz"
|
|
17
9
|
},
|
|
18
10
|
"main": "./dist-cjs/index.js",
|
|
19
11
|
"module": "./dist-es/index.js",
|
|
@@ -25,15 +17,9 @@
|
|
|
25
17
|
"license": "Apache-2.0",
|
|
26
18
|
"sideEffects": false,
|
|
27
19
|
"dependencies": {
|
|
20
|
+
"@smithy/core": "^3.24.0",
|
|
28
21
|
"tslib": "^2.6.2"
|
|
29
22
|
},
|
|
30
|
-
"typesVersions": {
|
|
31
|
-
"<4.0": {
|
|
32
|
-
"dist-types/*": [
|
|
33
|
-
"dist-types/ts3.4/*"
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
23
|
"files": [
|
|
38
24
|
"dist-*/**"
|
|
39
25
|
],
|
|
@@ -43,12 +29,6 @@
|
|
|
43
29
|
"url": "https://github.com/smithy-lang/smithy-typescript.git",
|
|
44
30
|
"directory": "packages/util-body-length-browser"
|
|
45
31
|
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"concurrently": "7.0.0",
|
|
48
|
-
"downlevel-dts": "0.10.1",
|
|
49
|
-
"premove": "4.0.0",
|
|
50
|
-
"typedoc": "0.23.23"
|
|
51
|
-
},
|
|
52
32
|
"typedoc": {
|
|
53
33
|
"entryPoint": "src/index.ts"
|
|
54
34
|
},
|
package/README.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# @smithy/util-body-length-browser
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@smithy/util-body-length-browser)
|
|
4
|
-
[](https://www.npmjs.com/package/@smithy/util-body-length-browser)
|
|
5
|
-
|
|
6
|
-
Determines the length of a request body in browsers
|
|
7
|
-
|
|
8
|
-
> An internal package
|
|
9
|
-
|
|
10
|
-
## Usage
|
|
11
|
-
|
|
12
|
-
You probably shouldn't, at least directly.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const TEXT_ENCODER = typeof TextEncoder == "function" ? new TextEncoder() : null;
|
|
2
|
-
export const calculateBodyLength = (body) => {
|
|
3
|
-
if (typeof body === "string") {
|
|
4
|
-
if (TEXT_ENCODER) {
|
|
5
|
-
return TEXT_ENCODER.encode(body).byteLength;
|
|
6
|
-
}
|
|
7
|
-
let len = body.length;
|
|
8
|
-
for (let i = len - 1; i >= 0; i--) {
|
|
9
|
-
const code = body.charCodeAt(i);
|
|
10
|
-
if (code > 0x7f && code <= 0x7ff)
|
|
11
|
-
len++;
|
|
12
|
-
else if (code > 0x7ff && code <= 0xffff)
|
|
13
|
-
len += 2;
|
|
14
|
-
if (code >= 0xdc00 && code <= 0xdfff)
|
|
15
|
-
i--;
|
|
16
|
-
}
|
|
17
|
-
return len;
|
|
18
|
-
}
|
|
19
|
-
else if (typeof body.byteLength === "number") {
|
|
20
|
-
return body.byteLength;
|
|
21
|
-
}
|
|
22
|
-
else if (typeof body.size === "number") {
|
|
23
|
-
return body.size;
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`Body Length computation failed for ${body}`);
|
|
26
|
-
};
|