Skip to content

Commit 468e495

Browse files
committed
2 parents 6c784c5 + 51213a6 commit 468e495

File tree

5 files changed

+66
-21
lines changed

5 files changed

+66
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Encapsulation of Nick Galbreath's base64.js library for AngularJS
44

5-
For Base64 encoding whch supports UTF8 see [angular-utf8-base64](https://github.com/stranger82/angular-utf8-base64)
5+
For Base64 encoding which supports UTF8 see [angular-utf8-base64](https://github.com/stranger82/angular-utf8-base64)
66

77
## Installation
88

@@ -18,6 +18,12 @@ bower install angular-base64
1818
<script src="bower_components/angular-base64/angular-base64.js"></script>
1919
```
2020

21+
### NPM
22+
23+
```
24+
npm i angular-base64
25+
```
26+
2127
## Usage
2228

2329
```javascript
@@ -33,6 +39,20 @@ angular
3339
}]);
3440
```
3541

42+
### Requiring NPM module when using Browserify
43+
44+
```javascript
45+
angular
46+
.module('myApp', [ require('angular-base64') ])
47+
.controller('myController', [
48+
'$base64', '$scope',
49+
function($base64, $scope) {
50+
51+
$scope.encoded = $base64.encode('a string');
52+
$scope.decoded = $base64.decode('YSBzdHJpbmc=');
53+
}]);
54+
```
55+
3656
### Unicode
3757

3858
You can encode unicode strings using base64 as described [here](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_.22Unicode_Problem.22).

angular-base64.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
function getbyte64(s,i) {
6464
var idx = ALPHA.indexOf(s.charAt(i));
65-
if (idx == -1) {
65+
if (idx === -1) {
6666
throw "Cannot decode base64";
6767
}
6868
return idx;
@@ -83,18 +83,18 @@
8383

8484
imax = s.length;
8585

86-
if (imax == 0) {
86+
if (imax === 0) {
8787
return s;
8888
}
8989

90-
if (imax % 4 != 0) {
90+
if (imax % 4 !== 0) {
9191
throw "Cannot decode base64";
9292
}
9393

9494
pads = 0;
95-
if (s.charAt(imax -1) == PADCHAR) {
95+
if (s.charAt(imax -1) === PADCHAR) {
9696
pads = 1;
97-
if (s.charAt(imax -2) == PADCHAR) {
97+
if (s.charAt(imax -2) === PADCHAR) {
9898
pads = 2;
9999
}
100100
// either way, we want to ignore this last block
@@ -130,7 +130,7 @@
130130
}
131131

132132
function encode(s) {
133-
if (arguments.length != 1) {
133+
if (arguments.length !== 1) {
134134
throw "SyntaxError: Not enough arguments";
135135
}
136136

@@ -142,7 +142,7 @@
142142

143143
var imax = s.length - s.length % 3;
144144

145-
if (s.length == 0) {
145+
if (s.length === 0) {
146146
return s;
147147
}
148148
for (i = 0; i < imax; i += 3) {

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Should already be required, just here for clarity
2+
require('angular');
3+
4+
// load the angular-base64 module
5+
require('./angular-base64.js')
6+
7+
module.exports = 'base64';

package.json

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
{
2-
"devDependencies": {
3-
"grunt": "",
4-
"grunt-cli": "",
5-
"grunt-contrib-clean": "",
6-
"grunt-contrib-copy": "",
7-
"grunt-contrib-jshint": "",
8-
"grunt-contrib-watch": "",
9-
"grunt-contrib-concat": "",
10-
"grunt-contrib-uglify": "",
11-
"grunt-notify": "",
12-
"grunt-strip": "",
13-
"grunt-text-replace": ""
14-
}
2+
"devDependencies": {
3+
"grunt": "",
4+
"grunt-cli": "",
5+
"grunt-contrib-clean": "",
6+
"grunt-contrib-copy": "",
7+
"grunt-contrib-jshint": "",
8+
"grunt-contrib-watch": "",
9+
"grunt-contrib-concat": "",
10+
"grunt-contrib-uglify": "",
11+
"grunt-notify": "",
12+
"grunt-strip": "",
13+
"grunt-text-replace": ""
14+
},
15+
"name": "@ninjatronic/angular-base64",
16+
"description": "Encapsulation of Nick Galbreath's base64.js library for AngularJS",
17+
"version": "0.0.2",
18+
"main": "index.js",
19+
"scripts": {
20+
"test": "echo \"Error: no test specified\" && exit 1"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": "git+https://github.com/ninjatronic/angular-base64.git"
25+
},
26+
"author": "",
27+
"license": "ISC",
28+
"bugs": {
29+
"url": "https://github.com/ninjatronic/angular-base64/issues"
30+
},
31+
"homepage": "https://github.com/ninjatronic/angular-base64#readme"
1532
}

0 commit comments

Comments
 (0)