Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live editor tweaks #233

Merged
merged 7 commits into from
Oct 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions live_editor/bower_components/angular-utf8-base64/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "angular-utf8-base64",
"version": "0.0.5",
"main": "angular-utf8-base64.js",
"ignore": [
"package.json",
"Gruntfile.js"
],
"dependencies": {
"angular": ">= 1.0.8"
},
"devDependencies": {
"angular-mocks": "~1.3.1"
},
"homepage": "https://github.com/stranger82/angular-utf8-base64",
"_release": "0.0.5",
"_resolution": {
"type": "version",
"tag": "v0.0.5",
"commit": "43cea612939acc07e06939f8da97e6f22186d1e2"
},
"_source": "git://github.com/stranger82/angular-utf8-base64.git",
"_target": "~0.0.5",
"_originalSource": "angular-utf8-base64",
"_direct": true
}
2 changes: 2 additions & 0 deletions live_editor/bower_components/angular-utf8-base64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bower_components
node_modules
29 changes: 29 additions & 0 deletions live_editor/bower_components/angular-utf8-base64/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"bitwise": true,
"curly": false,
"eqeqeq": true,
"eqnull": true,
"evil": true,
"forin": true,
"globalstrict": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"trailing": true,
"undef": true,
"unused": true,

"camelcase": true,
"indent": 4,
"quotmark": "single",

"predef": [
"angular",
"navigator",
"module" // Require
]
}

21 changes: 21 additions & 0 deletions live_editor/bower_components/angular-utf8-base64/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Andrey Bezyazychniy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions live_editor/bower_components/angular-utf8-base64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# angular-utf8-base64

AngularJS service for UTF-8 and Base64 and Base64url Javascript Encoding

angular-utf8-base64 is based on [Really fast Javascript Base64 encoder/decoder with utf-8 support](http://jsbase64.codeplex.com/releases/view/89265). I just wrapped it as AngularJS service.

There is another AngularJS service for Base64 encoding [available](https://github.com/ninjatronic/angular-base64).
But it doesn't support UTF-8.


## Installation

### Bower

```
bower install angular-utf8-base64
```

```html
<script src="bower_components/angular-utf8-base64/angular-utf8-base64.min.js"></script>
```

## Usage

```javascript
angular
.module('myApp', ['ab-base64'])
.controller('myController', [

'$scope','base64',
function($scope,base64) {

$scope.encoded = base64.encode('a string');
$scope.decoded = base64.decode('YSBzdHJpbmc=');
}]);
```

### Base64Url Support

Commonly used for supporting JWS and JWT encodings, base64url encoding creates a URL safe output.

```javascript
angular
.module('myApp', ['ab-base64'])
.controller('myController', [

'$scope','base64',
function($scope,base64) {

$scope.encoded = base64.urlencode('a string');
$scope.decoded = base64.urldecode('YSBzdHJpbmc');
}]);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
'use strict';

angular.module('ab-base64',[]).constant('base64', (function() {

/*
* Encapsulation of Vassilis Petroulias's base64.js library for AngularJS
* Original notice included below
*/

/*
Copyright Vassilis Petroulias [DRDigit]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var B64 = {
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
lookup: null,
ie: /MSIE /.test(navigator.userAgent),
ieo: /MSIE [67]/.test(navigator.userAgent),
encode: function (s) {
/* jshint bitwise:false */
var buffer = B64.toUtf8(s),
position = -1,
result,
len = buffer.length,
nan0, nan1, nan2, enc = [, , , ];

if (B64.ie) {
result = [];
while (++position < len) {
nan0 = buffer[position];
nan1 = buffer[++position];
enc[0] = nan0 >> 2;
enc[1] = ((nan0 & 3) << 4) | (nan1 >> 4);
if (isNaN(nan1))
enc[2] = enc[3] = 64;
else {
nan2 = buffer[++position];
enc[2] = ((nan1 & 15) << 2) | (nan2 >> 6);
enc[3] = (isNaN(nan2)) ? 64 : nan2 & 63;
}
result.push(B64.alphabet.charAt(enc[0]), B64.alphabet.charAt(enc[1]), B64.alphabet.charAt(enc[2]), B64.alphabet.charAt(enc[3]));
}
return result.join('');
} else {
result = '';
while (++position < len) {
nan0 = buffer[position];
nan1 = buffer[++position];
enc[0] = nan0 >> 2;
enc[1] = ((nan0 & 3) << 4) | (nan1 >> 4);
if (isNaN(nan1))
enc[2] = enc[3] = 64;
else {
nan2 = buffer[++position];
enc[2] = ((nan1 & 15) << 2) | (nan2 >> 6);
enc[3] = (isNaN(nan2)) ? 64 : nan2 & 63;
}
result += B64.alphabet[enc[0]] + B64.alphabet[enc[1]] + B64.alphabet[enc[2]] + B64.alphabet[enc[3]];
}
return result;
}
},
decode: function (s) {
/* jshint bitwise:false */
s = s.replace(/\s/g, '');
if (s.length % 4)
throw new Error('InvalidLengthError: decode failed: The string to be decoded is not the correct length for a base64 encoded string.');
if(/[^A-Za-z0-9+\/=\s]/g.test(s))
throw new Error('InvalidCharacterError: decode failed: The string contains characters invalid in a base64 encoded string.');

var buffer = B64.fromUtf8(s),
position = 0,
result,
len = buffer.length;

if (B64.ieo) {
result = [];
while (position < len) {
if (buffer[position] < 128)
result.push(String.fromCharCode(buffer[position++]));
else if (buffer[position] > 191 && buffer[position] < 224)
result.push(String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63)));
else
result.push(String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63)));
}
return result.join('');
} else {
result = '';
while (position < len) {
if (buffer[position] < 128)
result += String.fromCharCode(buffer[position++]);
else if (buffer[position] > 191 && buffer[position] < 224)
result += String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63));
else
result += String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63));
}
return result;
}
},
toUtf8: function (s) {
/* jshint bitwise:false */
var position = -1,
len = s.length,
chr, buffer = [];
if (/^[\x00-\x7f]*$/.test(s)) while (++position < len)
buffer.push(s.charCodeAt(position));
else while (++position < len) {
chr = s.charCodeAt(position);
if (chr < 128)
buffer.push(chr);
else if (chr < 2048)
buffer.push((chr >> 6) | 192, (chr & 63) | 128);
else
buffer.push((chr >> 12) | 224, ((chr >> 6) & 63) | 128, (chr & 63) | 128);
}
return buffer;
},
fromUtf8: function (s) {
/* jshint bitwise:false */
var position = -1,
len, buffer = [],
enc = [, , , ];
if (!B64.lookup) {
len = B64.alphabet.length;
B64.lookup = {};
while (++position < len)
B64.lookup[B64.alphabet.charAt(position)] = position;
position = -1;
}
len = s.length;
while (++position < len) {
enc[0] = B64.lookup[s.charAt(position)];
enc[1] = B64.lookup[s.charAt(++position)];
buffer.push((enc[0] << 2) | (enc[1] >> 4));
enc[2] = B64.lookup[s.charAt(++position)];
if (enc[2] === 64)
break;
buffer.push(((enc[1] & 15) << 4) | (enc[2] >> 2));
enc[3] = B64.lookup[s.charAt(++position)];
if (enc[3] === 64)
break;
buffer.push(((enc[2] & 3) << 6) | enc[3]);
}
return buffer;
}
};

var B64url = {
decode: function(input) {
// Replace non-url compatible chars with base64 standard chars
input = input
.replace(/-/g, '+')
.replace(/_/g, '/');

// Pad out with standard base64 required padding characters
var pad = input.length % 4;
if(pad) {
if(pad === 1) {
throw new Error('InvalidLengthError: Input base64url string is the wrong length to determine padding');
}
input += new Array(5-pad).join('=');
}

return B64.decode(input);
},

encode: function(input) {
var output = B64.encode(input);
return output
.replace(/\+/g, '-')
.replace(/\//g, '_')
.split('=', 1)[0];
}
};

return {
decode: B64.decode,
encode: B64.encode,
urldecode: B64url.decode,
urlencode: B64url.encode,
};
})());

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions live_editor/bower_components/angular-utf8-base64/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "angular-utf8-base64",
"version": "0.0.5",
"main": "angular-utf8-base64.js",
"ignore": [
"package.json",
"Gruntfile.js"
],
"dependencies": {
"angular": ">= 1.0.8"
},
"devDependencies": {
"angular-mocks": "~1.3.1"
}
}
Loading