>4),f[2]=a.lookup[b.charAt(++d)],64!==f[2])&&(e.push((15&f[1])<<4|f[2]>>2),f[3]=a.lookup[b.charAt(++d)],64!==f[3]);)e.push((3&f[2])<<6|f[3]);return e}},b={decode:function(b){b=b.replace(/-/g,"+").replace(/_/g,"/");var c=b.length%4;if(c){if(1===c)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");b+=new Array(5-c).join("=")}return a.decode(b)},encode:function(b){var c=a.encode(b);return c.replace(/\+/g,"-").replace(/\//g,"_").split("=",1)[0]}};return{decode:a.decode,encode:a.encode,urldecode:b.decode,urlencode:b.encode}}());
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-utf8-base64",
3 | "version": "0.0.5",
4 | "main": "angular-utf8-base64.js",
5 | "ignore": [
6 | "package.json",
7 | "Gruntfile.js"
8 | ],
9 | "dependencies": {
10 | "angular": ">= 1.0.8"
11 | },
12 | "devDependencies": {
13 | "angular-mocks": "~1.3.1"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | // Karma configuration
3 | // Generated on Mon Nov 03 2014 14:52:53 GMT-0700 (MST)
4 |
5 | module.exports = function(config) {
6 | config.set({
7 |
8 | // base path that will be used to resolve all patterns (eg. files, exclude)
9 | basePath: '',
10 |
11 |
12 | // frameworks to use
13 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
14 | frameworks: ['mocha', 'chai'],
15 |
16 |
17 | // list of files / patterns to load in the browser
18 | files: [
19 | 'bower_components/angular/angular.js',
20 | 'bower_components/angular-mocks/angular-mocks.js',
21 | 'angular-utf8-base64.js',
22 | 'test/**/*.spec.js'
23 | ],
24 |
25 |
26 | // list of files to exclude
27 | exclude: [
28 | ],
29 |
30 |
31 | // preprocess matching files before serving them to the browser
32 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
33 | preprocessors: {
34 | },
35 |
36 |
37 | // test results reporter to use
38 | // possible values: 'dots', 'progress'
39 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter
40 | reporters: ['progress'],
41 |
42 |
43 | // web server port
44 | port: 9876,
45 |
46 |
47 | // enable / disable colors in the output (reporters and logs)
48 | colors: true,
49 |
50 |
51 | // level of logging
52 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
53 | logLevel: config.LOG_INFO,
54 |
55 |
56 | // enable / disable watching file and executing tests whenever any file changes
57 | autoWatch: false,
58 |
59 |
60 | // start these browsers
61 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
62 | browsers: ['PhantomJS'],
63 |
64 |
65 | // Continuous Integration mode
66 | // if true, Karma captures browsers, runs the tests and exits
67 | singleRun: false
68 | });
69 | };
70 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-utf8-base64",
3 | "version": "0.0.5",
4 | "author": "stranger82",
5 | "description": "Base64 encoding/decoding with UTF8 support for AngularJS Apps",
6 | "contributors": [
7 | {
8 | "name": "Andrey Bezyazychniy",
9 | "email": "stranger82@gmail.com"
10 | }
11 | ],
12 | "repository": {
13 | "type": "git",
14 | "url": "https://github.com/stranger82/angular-utf8-base64.git"
15 | },
16 | "devDependencies": {
17 | "chai": "^1.9.2",
18 | "grunt": "^0.4.5",
19 | "grunt-contrib-clean": "^0.6.0",
20 | "grunt-contrib-jshint": "^0.10.0",
21 | "grunt-contrib-uglify": "^0.6.0",
22 | "grunt-contrib-watch": "^0.6.1",
23 | "grunt-karma": "^0.9.0",
24 | "grunt-notify": "^0.3.1",
25 | "karma": "^0.12.24",
26 | "karma-chai": "^0.1.0",
27 | "karma-mocha": "^0.1.9",
28 | "karma-phantomjs-launcher": "^0.1.4",
29 | "mocha": "^2.0.1"
30 | },
31 | "scripts": {
32 | "test": "grunt test"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/test/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "bitwise": true,
3 | "curly": false,
4 | "eqeqeq": true,
5 | "eqnull": true,
6 | "evil": true,
7 | "forin": true,
8 | "globalstrict": true,
9 | "immed": true,
10 | "latedef": true,
11 | "newcap": true,
12 | "noarg": true,
13 | "noempty": true,
14 | "nonew": true,
15 | "trailing": true,
16 | "undef": true,
17 | "unused": true,
18 |
19 | "camelcase": true,
20 | "indent": 4,
21 | "quotmark": "single",
22 |
23 | "globals": {
24 | // Mocha
25 | "describe": false,
26 | "it": false,
27 | "before": false,
28 | "beforeEach": false,
29 | "after": false,
30 | "afterEach": false,
31 |
32 | // chai
33 | "expect": false,
34 |
35 | // angular spec
36 | "module": false,
37 | "inject": false
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/test/angular-utf8-base64.spec.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var base64;
4 |
5 | beforeEach(module('ab-base64'));
6 | beforeEach(inject(function(_base64_) {
7 | base64 = _base64_;
8 | }));
9 |
10 | describe('base64 encode', function() {
11 | it('should encode simple ASCII', function() {
12 | expect(base64.encode('a string')).to.equal('YSBzdHJpbmc=');
13 | });
14 |
15 | it('should encode data with whitespace', function() {
16 | expect(base64.encode('a string\r\ta paragraph')).to.equal('YSBzdHJpbmcNCWEgcGFyYWdyYXBo');
17 | });
18 |
19 | it('should encode extended utf8', function() {
20 | expect(base64.encode('I ♥ base64')).to.equal('SSDimaUgYmFzZTY0');
21 | });
22 |
23 | it('should encode empty data', function() {
24 | expect(base64.encode('')).to.equal('');
25 | });
26 | });
27 |
28 | describe('base64 decode', function() {
29 | it('should decode simple ASCII', function() {
30 | expect(base64.decode('YSBzdHJpbmc=')).to.equal('a string');
31 | });
32 |
33 | it('should decode extended utf8', function() {
34 | expect(base64.decode('SSDimaUgYmFzZTY0')).to.equal('I ♥ base64');
35 | });
36 |
37 | it('should decode empty data', function() {
38 | expect(base64.decode('')).to.equal('');
39 | });
40 |
41 | it('should decode input with whitepace', function() {
42 | expect(base64.decode('YSBzd\r\t HJpbmc=')).to.equal('a string');
43 | });
44 |
45 | it('should throw on bad length', function() {
46 | expect(function() { base64.decode('235'); }).to.throw(/InvalidLengthError/);
47 | });
48 |
49 | it('should throw on bad characters', function() {
50 | expect(function() { base64.decode('!$#%'); }).to.throw(/InvalidCharacterError/);
51 | });
52 | });
53 |
54 | describe('base64url encode', function() {
55 | it('should encode simple ASCII', function() {
56 | expect(base64.urlencode('a string')).to.equal('YSBzdHJpbmc');
57 | });
58 |
59 | it('should only use URL safe characters ', function() {
60 | expect(base64.urlencode('So?I')).to.equal('U28_PHA-SQ');
61 | });
62 |
63 | it('should encode extended utf8', function() {
64 | expect(base64.urlencode('I ♥ me some base64url')).to.equal('SSDimaUgbWUgc29tZSBiYXNlNjR1cmw');
65 | });
66 | });
67 |
68 | describe('base64url decode', function() {
69 | it('should decode simple ASCII', function() {
70 | expect(base64.urldecode('YSBzdHJpbmc')).to.equal('a string');
71 | });
72 |
73 | it('should decode extended utf8', function() {
74 | expect(base64.urldecode('SSDimaUgbWUgc29tZSBiYXNlNjR1cmw')).to.equal('I ♥ me some base64url');
75 | });
76 |
77 | it('should decode with URL safe characters ', function() {
78 | expect(base64.urldecode('U28_PHA-SQ')).to.equal('So?
I');
79 | });
80 |
81 | it('should throw on invalid length', function() {
82 | expect(function() { base64.urldecode('SSDim'); }).to.throw(/InvalidLengthError/);
83 | });
84 | });
85 |
--------------------------------------------------------------------------------