Skip to content

Commit 9001c01

Browse files
committed
update to newest phin
1 parent 2a6ce70 commit 9001c01

File tree

5 files changed

+4383
-20
lines changed

5 files changed

+4383
-20
lines changed

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
Loads an [AngelCode BMFont](http://www.angelcode.com/products/bmfont/) file in browser (with XHR) and node (with fs and [phin](https://github.com/ethanent/phin)), returning a [JSON representation](json-spec.md).
66

77
```js
8-
var load = require('load-bmfont')
8+
var load = require("load-bmfont");
9+
10+
load("fonts/Arial-32.fnt", function (err, font) {
11+
if (err) throw err;
912

10-
load('fonts/Arial-32.fnt', function(err, font) {
11-
if (err)
12-
throw err
13-
1413
//The BMFont spec in JSON form
15-
console.log(font.common.lineHeight)
16-
console.log(font.info)
17-
console.log(font.chars)
18-
console.log(font.kernings)
19-
})
14+
console.log(font.common.lineHeight);
15+
console.log(font.info);
16+
console.log(font.chars);
17+
console.log(font.kernings);
18+
});
2019
```
2120

2221
Currently supported BMFont formats:
@@ -40,18 +39,21 @@ Loads a BMFont file with the `opt` settings and fires the callback with `(err, f
4039

4140
- `uri` or `url` the path (in Node) or URI
4241
- `binary` boolean, whether the data should be read as binary, default false
43-
- (in node) options for `fs.readFile` or `phin`
42+
- (in node) options for `fs.readFile` or [phin](https://www.npmjs.com/package/phin)
4443
- (in browser) options for [xhr](https://github.com/Raynos/xhr)
4544

4645
To support binary files in the browser and Node, you should use `binary: true`. Otherwise the XHR request might come in the form of a UTF8 string, which will not work with binary files. This also sets up the XHR object to override mime type in older browsers.
4746

4847
```js
49-
load({
50-
uri: 'fonts/Arial.bin',
51-
binary: true
52-
}, function(err, font) {
53-
console.log(font)
54-
})
48+
load(
49+
{
50+
uri: "fonts/Arial.bin",
51+
binary: true,
52+
},
53+
function (err, font) {
54+
console.log(font);
55+
}
56+
);
5557
```
5658

5759
## License

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ module.exports = function loadFont(opt, cb) {
4646
}
4747

4848
if (url.parse(file).host) {
49-
request(opt, handleData)
49+
request(opt).then(function (res) {
50+
handleData(null, res)
51+
}).catch(function (err) {
52+
handleData(err)
53+
})
5054
} else {
5155
fs.readFile(file, opt, handleData)
5256
}

0 commit comments

Comments
 (0)