s3-key

AWS S3 key utilities

Usage no npm install needed!

<script type="module">
  import s3Key from 'https://cdn.skypack.dev/s3-key';
</script>

README

S3-key

An AWS S3 utility library.

Usage

Install

  • yarn add s3-key

Polyfill

  • The project requires String.replaceAll. You need to polyfill it if your JavaScript engine doesn't support it.
import 'core-js/features/string/replace-all'

Exported functions

  • Sanitize an arbitrary string to a valid s3 key (such as converting space to plus).
export declare const sanitizeS3Key: (key: string, { charLimit = 512, replacementCharacter = '+', }?: {}) => string;
  • Extended version of encodeURI which encodes s3 key to URL string.
export declare const encodeS3Key: (key: string) => string;
  • Extended version of decodeURI which decode the value encoded by encodeS3Key.
export declare const decodeS3Key: (encodedKey: string) => string;

Advanced functions

  • AWS states that some characters should be avoided. But in fact, they still admit them. disallowAvoidedCharacters is an internal flag controlled by setDisallowAvoidedCharacters, is false by default. This flag should be disabled when we want a (better) one-to-one relationship between the input key and encodedKey such as in the image handler service.
export declare const setDisallowAvoidedCharacters: (val: boolean) => void;