Compare commits

...

25 Commits

Author SHA1 Message Date
712ae72156 update links 2019-04-17 08:16:35 -06:00
AJ ONeal
c5a3340a13 v2.1.7 2017-12-04 14:00:43 -07:00
AJ ONeal
49f9469bfd v2.1.5 2017-12-04 13:50:02 -07:00
AJ ONeal
c54fef010f v2.1.4 2017-12-04 13:49:40 -07:00
AJ ONeal
8b84926984 update urls 2017-12-04 13:49:26 -07:00
AJ ONeal
ed4674f721 merge 2017-01-03 00:06:38 -07:00
AJ ONeal
545cae0f21 auto-update banner 2016-12-30 02:41:19 -07:00
AJ ONeal
c439d0a170 auto-update ad 2016-12-30 00:53:43 -07:00
68b8abc469 Update README.md 2016-12-30 03:26:02 +00:00
AJ ONeal
df97310b71 Update README.md 2016-11-25 10:32:30 -07:00
AJ ONeal
76cb135585 Taking Back the Internet 2016-11-01 18:38:05 -06:00
AJ ONeal
a109259e10 Merge branch 'master' of github.com:coolaj86/unibabel-js 2015-11-17 15:13:36 -08:00
AJ ONeal
c4626055ff directory cleanup 2015-11-17 15:13:28 -08:00
AJ ONeal
20bed84814 name index.js for normal apis 2015-11-17 13:52:54 -08:00
AJ ONeal
e7c9b79676 fix spacing 2015-11-17 13:51:52 -08:00
AJ ONeal
66ab9f25b4 fix comma 2015-11-17 13:40:30 -08:00
AJ ONeal
bde896c451 publish to npm for browsers as per #7 2015-11-17 13:35:32 -08:00
AJ ONeal
c67e0582f3 Update README.md 2015-11-17 13:18:30 -08:00
AJ ONeal
aafbc0e083 quickie tut for #7 2015-11-17 13:17:52 -08:00
AJ ONeal
ba0b45c7e8 Update README.md 2015-11-17 13:10:17 -08:00
AJ ONeal
ca845c0080 Update README.md 2015-10-27 13:40:53 -07:00
AJ ONeal
73eb31e1ed Update README.md 2015-10-27 13:40:39 -07:00
AJ ONeal
f9c33cc112 bump 2015-10-23 03:13:58 -07:00
AJ ONeal
8cd0bc48ec Merge branch 'master' of github.com:coolaj86/unibabel-js 2015-10-23 03:13:34 -07:00
AJ ONeal
ea400ab670 polyfill Mobile Safari's missing slice 2015-10-23 03:13:27 -07:00
13 changed files with 144 additions and 21 deletions

32
LICENSE
View File

@ -1,3 +1,32 @@
At your option you may choose either of the following licenses:
* The MIT License (MIT)
* The Apache License 2.0 (Apache-2.0)
The MIT License (MIT)
Copyright (c) 2015 AJ ONeal
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.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@ -186,7 +215,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Copyright 2015 AJ ONeal
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -199,4 +228,3 @@
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.

View File

@ -1,7 +1,7 @@
Unibabel
========
Minimalistic Base64, TypedArrays, and UTF-8 / Unicode conversions in Browser (and Node) JavaScript
Minimalistic **Base64**, **TypedArrays**, and **UTF-8** / **Unicode** conversions in Browser (and Node) JavaScript. Optional add-on support for **hex** and **base32**.
See <https://coolaj86.com/articles/base64-unicode-utf-8-javascript-and-you/>
@ -14,6 +14,41 @@ See also
* [TextEncoderLite (based on text-encoding)](https://github.com/coolaj86/TextEncoderLite/tree/lite)
* [Beatgammit's base64-js](https://github.com/beatgammit/base64-js)
Are you in the right place?
------------------------
Dear Node.js Users:
You SHOULD NOT use this module. You already have [`Buffer`](https://nodejs.org/api/buffer.html) and [`thirty-two`](https://github.com/chrisumbel/thirty-two):
```javascript
var buf = new Buffer('I ½ ♥ 💩', 'utf8');
buf.toString('hex');
buf.toString('base64');
buf.toString('ascii');
buf.toString('utf8');
buf.toString('binary'); // deprecated, do not use
```
Install
-------
You just include the `index.js` in a lovely script tag.
```bash
bower install --save unibabel
```
```html
<script src="/bower_components/unibabel/index.js"></script>
```
Dear WebPack / Broccoli, Gulp / Grunt Users:
I don't know how your build systems work these days,
but Unibabel is exported as `Unibabel`
and you can access it as `window.Unibabel`.
API
===
@ -29,12 +64,12 @@ var uint8Array = Unibabel.base64ToArr(base64)
**Normal APIs**
`index.js`
* utf8ToBuffer(utf8str) => array
* bufferToUtf8(array) => string
* utf8ToBase64(utf8str) => base64
* base64ToUtf8(base64) => string
* bufferToBase64(array) => base64
* base64ToBuffer(base64) => array

View File

@ -1,10 +1,9 @@
{
"name": "unibabel",
"main": "index.js",
"version": "2.1.1",
"homepage": "https://github.com/coolaj86/unibabel-js",
"homepage": "https://git.coolaj86.com/coolaj86/unibabel.js",
"authors": [
"AJ ONeal <awesome@coolaj86.com>"
"AJ ONeal <coolaj86@gmail.com>"
],
"description": "Convert between UTF8, TypedArrays, and Base64",
"moduleType": [
@ -12,15 +11,21 @@
"node"
],
"keywords": [
"ascii",
"binary",
"utf8",
"utf-8",
"ArrayBuffer",
"TypedArrays",
"TypedArray",
"Uint",
"Uint8Array",
"Base64",
"b64"
"b64",
"Base32",
"b32"
],
"license": "Apache2",
"license": "Apache-2.0",
"ignore": [
"**/.*",
"node_modules",

View File

@ -4,9 +4,9 @@
</head>
<body>
This is for testing. Look in the console.
<script src="./index.js"></script>
<script src="./unibabel.hex.js"></script>
<script src="./unibabel.base32.js"></script>
<script src="../index.js"></script>
<script src="../unibabel.hex.js"></script>
<script src="../unibabel.base32.js"></script>
<script src="./test.js"></script>
</body>
</html>

View File

@ -1,4 +1,4 @@
(function () {
(function (exports) {
'use strict';
function utf8ToBinaryString(str) {
@ -82,7 +82,7 @@ function base64ToBuffer(base64) {
return buf;
}
window.Unibabel = {
exports.Unibabel = {
utf8ToBinaryString: utf8ToBinaryString
, utf8ToBuffer: utf8ToBuffer
, utf8ToBase64: utf8ToBase64
@ -101,4 +101,4 @@ window.Unibabel = {
, base64ToArr: base64ToBuffer
};
}());
}('undefined' !== typeof exports && exports || 'undefined' !== typeof window && window || global));

19
node.js Normal file
View File

@ -0,0 +1,19 @@
'use strict';
console.warn("Please don't use Unibabel in node.js. If you think you really think you have a valid use case please report it at https://git.coolaj86.com/coolaj86/unibabel.js/issues/new");
throw new Error("[unibabel] you're doing it wrong");
/*
var data = 'I ½ ♥ 💩';
var encoding = 'utf8';
var buf = new Buffer(data, encoding);
buf.toString('hex');
buf.toString('base64');
buf.toString('ascii');
buf.toString('utf8');
buf.toString('binary'); // deprecated, do not use
var Base32 = require('thirty-two');
var b32 = Base32.encode(buf);
Base32.decode(buf);
*/

37
package.json Normal file
View File

@ -0,0 +1,37 @@
{
"name": "unibabel",
"version": "2.1.8",
"description": "Base64, TypedArrays, and UTF-8 / Unicode conversions in Browser (and Node) JavaScript",
"main": "node.js",
"browser": {
"./node.js": "./index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.coolaj86.com/coolaj86/unibabel.js.git"
},
"keywords": [
"ascii",
"binary",
"utf8",
"utf-8",
"ArrayBuffer",
"TypedArrays",
"TypedArray",
"Uint",
"Uint8Array",
"Base64",
"b64",
"Base32",
"b32"
],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
"license": "(MIT OR Apache-2.0)",
"bugs": {
"url": "https://git.coolaj86.com/coolaj86/unibabel.js/issues"
},
"homepage": "https://git.coolaj86.com/coolaj86/unibabel.js#readme"
}

View File

@ -1 +0,0 @@
index.js

View File

@ -131,11 +131,11 @@ exports.base32ToBuffer = function(encoded) {
throw new Error('Invalid input - it is not base32 encoded string');
}
}
if (decoded.slice) {
if (decoded.slice) { // Array or TypedArray
return decoded.slice(0, plainPos);
} else {
// Mobile Safari's Uint8Array doesn't have slice
return Array.prototype.slice.call(decoded, 0, plainPos);
} else { // Mobile Safari TypedArray
return new Uint8Array(Array.prototype.slice.call(decoded, 0, plainPos));
}
};