@aws-amplify/core
Version:
Core category of aws-amplify
21 lines (19 loc) • 427 B
text/typescript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
export function urlSafeEncode(str: string) {
return str
.split('')
.map(char =>
char
.charCodeAt(0)
.toString(16)
.padStart(2, '0')
)
.join('');
}
export function urlSafeDecode(hex: string) {
return hex
.match(/.{2}/g)
.map(char => String.fromCharCode(parseInt(char, 16)))
.join('');
}