@smithy/util-body-length-browser 4.0.0 → 4.2.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 +26 -53
- package/package.json +5 -4
- package/dist-cjs/calculateBodyLength.js +0 -1
package/dist-cjs/index.js
CHANGED
|
@@ -1,57 +1,30 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
26
2
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
3
|
+
const TEXT_ENCODER = typeof TextEncoder == "function" ? new TextEncoder() : null;
|
|
4
|
+
const calculateBodyLength = (body) => {
|
|
5
|
+
if (typeof body === "string") {
|
|
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;
|
|
33
20
|
}
|
|
34
|
-
|
|
35
|
-
|
|
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--;
|
|
21
|
+
else if (typeof body.byteLength === "number") {
|
|
22
|
+
return body.byteLength;
|
|
43
23
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
54
|
-
0 && (module.exports = {
|
|
55
|
-
calculateBodyLength
|
|
56
|
-
});
|
|
24
|
+
else if (typeof body.size === "number") {
|
|
25
|
+
return body.size;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Body Length computation failed for ${body}`);
|
|
28
|
+
};
|
|
57
29
|
|
|
30
|
+
exports.calculateBodyLength = calculateBodyLength;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.2.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
7
7
|
"build:cjs": "node ../../scripts/inline util-body-length-browser",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
|
|
12
12
|
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
|
|
13
13
|
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
|
|
14
|
-
"format": "prettier --config ../../prettier.config.js --ignore-path
|
|
14
|
+
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
|
|
15
15
|
"test": "yarn g:vitest run",
|
|
16
16
|
"test:watch": "yarn g:vitest watch"
|
|
17
17
|
},
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"url": "https://aws.amazon.com/javascript/"
|
|
24
24
|
},
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
|
+
"sideEffects": false,
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"tslib": "^2.6.2"
|
|
28
29
|
},
|
|
@@ -36,10 +37,10 @@
|
|
|
36
37
|
"files": [
|
|
37
38
|
"dist-*/**"
|
|
38
39
|
],
|
|
39
|
-
"homepage": "https://github.com/
|
|
40
|
+
"homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/util-body-length-browser",
|
|
40
41
|
"repository": {
|
|
41
42
|
"type": "git",
|
|
42
|
-
"url": "https://github.com/
|
|
43
|
+
"url": "https://github.com/smithy-lang/smithy-typescript.git",
|
|
43
44
|
"directory": "packages/util-body-length-browser"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|