@azure/core-util
Advanced tools
Comparing version 1.3.3-alpha.20230727.2 to 1.4.0-alpha.20230803.2
@@ -12,2 +12,3 @@ // Copyright (c) Microsoft Corporation. | ||
export { isBrowser, isBun, isNode, isDeno, isReactNative, isWebWorker } from "./checkEnvironment"; | ||
export { uint8ArrayToString, stringToUint8Array } from "./bytesEncoding"; | ||
//# sourceMappingURL=index.js.map |
@@ -288,2 +288,79 @@ 'use strict'; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* The helper that transforms bytes with specific character encoding into string | ||
* @param bytes - the uint8array bytes | ||
* @param format - the format we use to encode the byte | ||
* @returns a string of the encoded string | ||
*/ | ||
function uint8ArrayToString(bytes, format) { | ||
switch (format) { | ||
case "utf-8": | ||
return uint8ArrayToUtf8String(bytes); | ||
case "base64": | ||
return uint8ArrayToBase64(bytes); | ||
case "base64url": | ||
return uint8ArrayToBase64Url(bytes); | ||
} | ||
} | ||
/** | ||
* The helper that transforms string to specific character encoded bytes array. | ||
* @param value - the string to be converted | ||
* @param format - the format we use to decode the value | ||
* @returns a uint8array | ||
*/ | ||
function stringToUint8Array(value, format) { | ||
switch (format) { | ||
case "utf-8": | ||
return utf8StringToUint8Array(value); | ||
case "base64": | ||
return base64ToUint8Array(value); | ||
case "base64url": | ||
return base64UrlToUint8Array(value); | ||
} | ||
} | ||
/** | ||
* Decodes a Uint8Array into a Base64 string. | ||
* @internal | ||
*/ | ||
function uint8ArrayToBase64(bytes) { | ||
return Buffer.from(bytes).toString("base64"); | ||
} | ||
/** | ||
* Decodes a Uint8Array into a Base64Url string. | ||
* @internal | ||
*/ | ||
function uint8ArrayToBase64Url(bytes) { | ||
return Buffer.from(bytes).toString("base64url"); | ||
} | ||
/** | ||
* Decodes a Uint8Array into a javascript string. | ||
* @internal | ||
*/ | ||
function uint8ArrayToUtf8String(bytes) { | ||
return Buffer.from(bytes).toString("utf-8"); | ||
} | ||
/** | ||
* Encodes a JavaScript string into a Uint8Array. | ||
* @internal | ||
*/ | ||
function utf8StringToUint8Array(value) { | ||
return Buffer.from(value); | ||
} | ||
/** | ||
* Encodes a Base64 string into a Uint8Array. | ||
* @internal | ||
*/ | ||
function base64ToUint8Array(value) { | ||
return Buffer.from(value, "base64"); | ||
} | ||
/** | ||
* Encodes a Base64Url string into a Uint8Array. | ||
* @internal | ||
*/ | ||
function base64UrlToUint8Array(value) { | ||
return Buffer.from(value, "base64url"); | ||
} | ||
exports.computeSha256Hash = computeSha256Hash; | ||
@@ -307,2 +384,4 @@ exports.computeSha256Hmac = computeSha256Hmac; | ||
exports.randomUUID = randomUUID; | ||
exports.stringToUint8Array = stringToUint8Array; | ||
exports.uint8ArrayToString = uint8ArrayToString; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@azure/core-util", | ||
"version": "1.3.3-alpha.20230727.2", | ||
"version": "1.4.0-alpha.20230803.2", | ||
"description": "Core library for shared utility methods", | ||
@@ -10,3 +10,4 @@ "sdk-type": "client", | ||
"./dist-esm/src/sha256.js": "./dist-esm/src/sha256.browser.js", | ||
"./dist-esm/src/uuidUtils.js": "./dist-esm/src/uuidUtils.browser.js" | ||
"./dist-esm/src/uuidUtils.js": "./dist-esm/src/uuidUtils.browser.js", | ||
"./dist-esm/src/bytesEncoding.js": "./dist-esm/src/bytesEncoding.browser.js" | ||
}, | ||
@@ -13,0 +14,0 @@ "react-native": { |
@@ -53,2 +53,4 @@ import { AbortSignalLike } from '@azure/abort-controller'; | ||
} | ||
/** The supported character encoding type */ | ||
export declare type EncodingType = "utf-8" | "base64" | "base64url"; | ||
/** | ||
@@ -128,2 +130,16 @@ * Given what is thought to be an error object, return the message if possible. | ||
/** | ||
* The helper that transforms string to specific character encoded bytes array. | ||
* @param value - the string to be converted | ||
* @param format - the format we use to decode the value | ||
* @returns a uint8array | ||
*/ | ||
export declare function stringToUint8Array(value: string, format: EncodingType): Uint8Array; | ||
/** | ||
* The helper that transforms bytes with specific character encoding into string | ||
* @param bytes - the uint8array bytes | ||
* @param format - the format we use to encode the byte | ||
* @returns a string of the encoded string | ||
*/ | ||
export declare function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string; | ||
/** | ||
* A generic shape for a plain JS object. | ||
@@ -130,0 +146,0 @@ */ |
@@ -60,2 +60,5 @@ import { AbortSignalLike } from '@azure/abort-controller'; | ||
/** The supported character encoding type */ | ||
export declare type EncodingType = "utf-8" | "base64" | "base64url"; | ||
/** | ||
@@ -149,2 +152,18 @@ * Given what is thought to be an error object, return the message if possible. | ||
/** | ||
* The helper that transforms string to specific character encoded bytes array. | ||
* @param value - the string to be converted | ||
* @param format - the format we use to decode the value | ||
* @returns a uint8array | ||
*/ | ||
export declare function stringToUint8Array(value: string, format: EncodingType): Uint8Array; | ||
/** | ||
* The helper that transforms bytes with specific character encoding into string | ||
* @param bytes - the uint8array bytes | ||
* @param format - the format we use to encode the byte | ||
* @returns a string of the encoded string | ||
*/ | ||
export declare function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string; | ||
/** | ||
* A generic shape for a plain JS object. | ||
@@ -151,0 +170,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119275
43
1279