1 | 'use strict';
|
2 |
|
3 | var stripBom = require('strip-bom-string');
|
4 | exports.typeOf = require('kind-of');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | exports.isBuffer = function(val) {
|
11 | return exports.typeOf(val) === 'buffer';
|
12 | };
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | exports.isObject = function(val) {
|
19 | return exports.typeOf(val) === 'object';
|
20 | };
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | exports.toBuffer = function(input) {
|
27 | if (typeof input === 'string') {
|
28 | return new Buffer(input);
|
29 | }
|
30 | return input;
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | exports.toString = function(input) {
|
38 | if (exports.isBuffer(input)) {
|
39 | return stripBom(String(input));
|
40 | }
|
41 | if (typeof input !== 'string') {
|
42 | throw new TypeError('expected input to be a string or buffer');
|
43 | }
|
44 | return stripBom(input);
|
45 | };
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | exports.arrayify = function(val) {
|
52 | return val ? (Array.isArray(val) ? val : [val]) : [];
|
53 | };
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | exports.startsWith = function(str, substr, len) {
|
60 | if (typeof len !== 'number') len = substr.length;
|
61 | return str.slice(0, len) === substr;
|
62 | };
|