S3 Bucket Name Validator
Follows official latest rules published here. Implementation stolen from Serverless
Install
$ yarn add s3-bucket-name-validator
Usage
const validateS3BucketName = ; // Returns error string with reason if invalid. Empty string otherwise const bucketNameError = ; // 'Bucket name must start with a letter or number. -invalid.name'if bucketNameError // ... some logic ; // ''
Reference
This code was grabbed from AWS S3 front-end
Click to expand obfuscated code 😰
URL: d3v76wtu1o9bby.cloudfront.net/js/s3_console_Prod.gz.js
this { var B = argumentslength <= 1 || arguments1 === undefined ? : arguments1; if !D B; return false var F = "\0"; var H = ""; for var C = 0; C < Dlength; C++ var E = D; var G = ""; if /[A-Z]/ var I = t; if B === -1 B if E === "." if F === "\0" G = t if F === "." G = t if F === "-" G = t else if E === "-" if F === "\0" G = t if F === "." G = t else if !/[a-z0-9]/ && H === -1 if !/[A-Z]/ H += E if F === "\0" G = t if G && B === -1 B F = E if F === "." || F === "-" B if Hlength > 0 B if Dlength < 3 || Dlength > 63 B if /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ B return Blength === 0}