Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div>
  <p>Base64, Base64URL and ArrayBuffer</p>
</div>
<script src="index.js"></script>
              
            
!

CSS

              
                
              
            
!

JS

              
                function base642ab(base64) {
  const str = window.atob(base64);
  const len = str.length;
  const bytes = new Uint16Array(len);
  for (let i = 0; i < len; i++) {
    bytes[i] = str.charCodeAt(i);
  }
  return bytes.buffer;
}

function ab2base64(ab) {
  const str = String.fromCharCode.apply(null, new Uint16Array(ab))
  return window.btoa(str);
}

function base64url2ab(base64url) {
  return base642ab(base64url2base64(base64url));
}

function ab2base64url(ab) {
  const str = String.fromCharCode.apply(null, new Uint16Array(ab))
  return base642base64url(window.btoa(str));  
}

function base642base64url(base64) {
  return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=*$/g, '')
}

function base64url2base64(base64url) {
  let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
  const padding = base64.length % 4;
  if (padding > 0) {
    return base64 + '===='.slice(padding);
  } 
  return base64;
}

(function () {
  let str = "I hope to hell that when I do die somebody has the sense to just dump me in the river or something";
  console.log(str);
  let base64 = window.btoa(str);
  console.log(base64);
  let base64AB = base642ab(base64);
  console.log(base64AB);
  let base642 = ab2base64(base64AB);
  console.log(base642);
  let str2 = window.atob(base642);
  console.log(str2);
  
  console.log("====");
  
  console.log(str);
  let base643 = window.btoa(str);
  console.log(base643);
  let base64url = base642base64url(base643);
  console.log(base64url);
  let base64urlAB = base64url2ab(base64url);
  console.log(base64urlAB);
  let base64url2 = ab2base64url(base64urlAB);
  console.log(base64url2);
  let base644 = base64url2base64(base64url2);
  console.log(base644);
  let str3 = window.atob(base644);
  console.log(str3)  
}());
              
            
!
999px

Console