summaryrefslogtreecommitdiff
path: root/node_modules/gray-matter/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/gray-matter/lib/utils.js')
-rw-r--r--node_modules/gray-matter/lib/utils.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/node_modules/gray-matter/lib/utils.js b/node_modules/gray-matter/lib/utils.js
new file mode 100644
index 0000000..96e7ce0
--- /dev/null
+++ b/node_modules/gray-matter/lib/utils.js
@@ -0,0 +1,66 @@
+'use strict';
+
+const stripBom = require('strip-bom-string');
+const typeOf = require('kind-of');
+
+exports.define = function(obj, key, val) {
+ Reflect.defineProperty(obj, key, {
+ enumerable: false,
+ configurable: true,
+ writable: true,
+ value: val
+ });
+};
+
+/**
+ * Returns true if `val` is a buffer
+ */
+
+exports.isBuffer = function(val) {
+ return typeOf(val) === 'buffer';
+};
+
+/**
+ * Returns true if `val` is an object
+ */
+
+exports.isObject = function(val) {
+ return typeOf(val) === 'object';
+};
+
+/**
+ * Cast `input` to a buffer
+ */
+
+exports.toBuffer = function(input) {
+ return typeof input === 'string' ? Buffer.from(input) : input;
+};
+
+/**
+ * Cast `val` to a string.
+ */
+
+exports.toString = function(input) {
+ if (exports.isBuffer(input)) return stripBom(String(input));
+ if (typeof input !== 'string') {
+ throw new TypeError('expected input to be a string or buffer');
+ }
+ return stripBom(input);
+};
+
+/**
+ * Cast `val` to an array.
+ */
+
+exports.arrayify = function(val) {
+ return val ? (Array.isArray(val) ? val : [val]) : [];
+};
+
+/**
+ * Returns true if `str` starts with `substr`.
+ */
+
+exports.startsWith = function(str, substr, len) {
+ if (typeof len !== 'number') len = substr.length;
+ return str.slice(0, len) === substr;
+};