🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@smithy/util-utf8

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/util-utf8 - npm Package Compare versions

Comparing version
4.2.2
to
4.3.0
+7
-32
dist-cjs/index.js

@@ -1,32 +0,7 @@

'use strict';
var utilBufferFrom = require('@smithy/util-buffer-from');
const fromUtf8 = (input) => {
const buf = utilBufferFrom.fromString(input, "utf8");
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
};
const toUint8Array = (data) => {
if (typeof data === "string") {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
return new Uint8Array(data);
};
const toUtf8 = (input) => {
if (typeof input === "string") {
return input;
}
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
}
return utilBufferFrom.fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("utf8");
};
exports.fromUtf8 = fromUtf8;
exports.toUint8Array = toUint8Array;
exports.toUtf8 = toUtf8;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUtf8 = exports.toUint8Array = exports.fromUtf8 = void 0;
var serde_1 = require("@smithy/core/serde");
Object.defineProperty(exports, "fromUtf8", { enumerable: true, get: function () { return serde_1.fromUtf8; } });
Object.defineProperty(exports, "toUint8Array", { enumerable: true, get: function () { return serde_1.toUint8Array; } });
Object.defineProperty(exports, "toUtf8", { enumerable: true, get: function () { return serde_1.toUtf8; } });
+1
-3

@@ -1,3 +0,1 @@

export * from "./fromUtf8";
export * from "./toUint8Array";
export * from "./toUtf8";
export { fromUtf8, toUint8Array, toUtf8 } from "@smithy/core/serde";

@@ -1,3 +0,3 @@

export * from "./fromUtf8";
export * from "./toUint8Array";
export * from "./toUtf8";
/** @deprecated Use @smithy/core/serde instead. */
export { fromUtf8, toUint8Array, toUtf8 } from "@smithy/core/serde";
export type { StringEncoding } from "@smithy/core/serde";
{
"name": "@smithy/util-utf8",
"version": "4.2.2",
"version": "4.3.0",
"description": "A UTF-8 string <-> UInt8Array converter",

@@ -8,13 +8,5 @@ "main": "./dist-cjs/index.js",

"scripts": {
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
"build:cjs": "node ../../scripts/inline util-utf8",
"build:es": "yarn g:tsc -p tsconfig.es.json",
"build:types": "yarn g:tsc -p tsconfig.types.json",
"build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
"stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
"clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:vitest run",
"test:watch": "yarn g:vitest watch"
"build": "yarn g:tsc -p tsconfig.cjs.json && yarn g:tsc -p tsconfig.es.json && yarn g:tsc -p tsconfig.types.json",
"clean": "rm -rf dist-cjs dist-es dist-types",
"stage-release": "rm -rf .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz"
},

@@ -28,11 +20,5 @@ "author": {

"dependencies": {
"@smithy/util-buffer-from": "^4.2.2",
"@smithy/core": "^3.24.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
"premove": "4.0.0",
"typedoc": "0.23.23"
},
"types": "./dist-types/index.d.ts",

@@ -42,17 +28,5 @@ "engines": {

},
"typesVersions": {
"<4.5": {
"dist-types/*": [
"dist-types/ts3.4/*"
]
}
},
"files": [
"dist-*/**"
],
"browser": {
"./dist-es/fromUtf8": "./dist-es/fromUtf8.browser",
"./dist-es/toUtf8": "./dist-es/toUtf8.browser"
},
"react-native": {},
"homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/util-utf8",

@@ -59,0 +33,0 @@ "repository": {

export const fromUtf8 = (input) => new TextEncoder().encode(input);
import { fromString } from "@smithy/util-buffer-from";
export const fromUtf8 = (input) => {
const buf = fromString(input, "utf8");
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
};
import { fromUtf8 } from "./fromUtf8";
export const toUint8Array = (data) => {
if (typeof data === "string") {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
return new Uint8Array(data);
};
export const toUtf8 = (input) => {
if (typeof input === "string") {
return input;
}
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
}
return new TextDecoder("utf-8").decode(input);
};
import { fromArrayBuffer } from "@smithy/util-buffer-from";
export const toUtf8 = (input) => {
if (typeof input === "string") {
return input;
}
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
}
return fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("utf8");
};
export declare const fromUtf8: (input: string) => Uint8Array;
export declare const fromUtf8: (input: string) => Uint8Array;
export declare const toUint8Array: (data: string | ArrayBuffer | ArrayBufferView) => Uint8Array;
/**
*
* This does not convert non-utf8 strings to utf8, it only passes through strings if
* a string is received instead of a Uint8Array.
*
*/
export declare const toUtf8: (input: Uint8Array | string) => string;
/**
*
* This does not convert non-utf8 strings to utf8, it only passes through strings if
* a string is received instead of a Uint8Array.
*
*/
export declare const toUtf8: (input: Uint8Array | string) => string;
export declare const fromUtf8: (input: string) => Uint8Array;
export declare const fromUtf8: (input: string) => Uint8Array;
export * from "./fromUtf8";
export * from "./toUint8Array";
export * from "./toUtf8";
export declare const toUint8Array: (data: string | ArrayBuffer | ArrayBufferView) => Uint8Array;
/**
*
* This does not convert non-utf8 strings to utf8, it only passes through strings if
* a string is received instead of a Uint8Array.
*
*/
export declare const toUtf8: (input: Uint8Array | string) => string;
/**
*
* This does not convert non-utf8 strings to utf8, it only passes through strings if
* a string is received instead of a Uint8Array.
*
*/
export declare const toUtf8: (input: Uint8Array | string) => string;
# @smithy/util-utf8
[![NPM version](https://img.shields.io/npm/v/@smithy/util-utf8/latest.svg)](https://www.npmjs.com/package/@smithy/util-utf8)
[![NPM downloads](https://img.shields.io/npm/dm/@smithy/util-utf8.svg)](https://www.npmjs.com/package/@smithy/util-utf8)