@jaredwray/fumanchu 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/object.js DELETED
@@ -1,290 +0,0 @@
1
- 'use strict';
2
-
3
- var hasOwn = Object.hasOwnProperty;
4
- var util = require('handlebars-utils');
5
- var array = require('./array');
6
- var utils = require('./utils/');
7
- var helpers = module.exports;
8
-
9
- /**
10
- * Extend the context with the properties of other objects.
11
- * A shallow merge is performed to avoid mutating the context.
12
- *
13
- * @param {Object} `objects` One or more objects to extend.
14
- * @return {Object}
15
- * @api public
16
- */
17
-
18
- helpers.extend = function(/*objects*/) {
19
- var args = [].slice.call(arguments);
20
- var opts = {};
21
-
22
- if (util.isOptions(args[args.length - 1])) {
23
- // remove handlebars options object
24
- opts = args.pop().hash;
25
- // re-add handlebars options.hash object
26
- args.push(opts);
27
- }
28
-
29
- var context = {};
30
- for (var i = 0; i < args.length; i++) {
31
- var obj = args[i];
32
- if (util.isObject(obj)) {
33
- var keys = Object.keys(obj);
34
- for (var j = 0; j < keys.length; j++) {
35
- var key = keys[j];
36
- context[key] = obj[key];
37
- }
38
- }
39
- }
40
-
41
- return context;
42
- };
43
-
44
- /**
45
- * Block helper that iterates over the properties of
46
- * an object, exposing each key and value on the context.
47
- *
48
- * @param {Object} `context`
49
- * @param {Object} `options`
50
- * @return {String}
51
- * @block
52
- * @api public
53
- */
54
-
55
- helpers.forIn = function(obj, options) {
56
- if (!util.isOptions(options)) {
57
- return obj.inverse(this);
58
- }
59
-
60
- var data = utils.createFrame(options, options.hash);
61
- var result = '';
62
-
63
- for (var key in obj) {
64
- data.key = key;
65
- result += options.fn(obj[key], {data: data});
66
- }
67
- return result;
68
- };
69
-
70
- /**
71
- * Block helper that iterates over the **own** properties of
72
- * an object, exposing each key and value on the context.
73
- *
74
- * @param {Object} `obj` The object to iterate over.
75
- * @param {Object} `options`
76
- * @return {String}
77
- * @block
78
- * @api public
79
- */
80
-
81
- helpers.forOwn = function(obj, options) {
82
- if (!util.isOptions(options)) {
83
- return obj.inverse(this);
84
- }
85
-
86
- var data = utils.createFrame(options, options.hash);
87
- var result = '';
88
-
89
- for (var key in obj) {
90
- if (obj.hasOwnProperty(key)) {
91
- data.key = key;
92
- result += options.fn(obj[key], {data: data});
93
- }
94
- }
95
- return result;
96
- };
97
-
98
- /**
99
- * Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
100
- *
101
- * @param {String|Number} `prop` The property segments to assemble (can be multiple).
102
- * @return {String}
103
- * @api public
104
- */
105
-
106
- helpers.toPath = function(/*prop*/) {
107
- var prop = [];
108
- for (var i = 0; i < arguments.length; i++) {
109
- if (typeof arguments[i] === 'string' || typeof arguments[i] === 'number') {
110
- prop.push(arguments[i]);
111
- }
112
- }
113
- return prop.join('.');
114
- };
115
-
116
- /**
117
- * Use property paths (`a.b.c`) to get a value or nested value from
118
- * the context. Works as a regular helper or block helper.
119
- *
120
- * @param {String} `prop` The property to get, optionally using dot notation for nested properties.
121
- * @param {Object} `context` The context object
122
- * @param {Object} `options` The handlebars options object, if used as a block helper.
123
- * @return {String}
124
- * @block
125
- * @api public
126
- */
127
-
128
- helpers.get = function(prop, context, options) {
129
- var val = utils.get(context, prop);
130
- if (options && options.fn) {
131
- return val ? options.fn(val) : options.inverse(context);
132
- }
133
- return val;
134
- };
135
-
136
- /**
137
- * Use property paths (`a.b.c`) to get an object from
138
- * the context. Differs from the `get` helper in that this
139
- * helper will return the actual object, including the
140
- * given property key. Also, this helper does not work as a
141
- * block helper.
142
- *
143
- * @param {String} `prop` The property to get, optionally using dot notation for nested properties.
144
- * @param {Object} `context` The context object
145
- * @return {String}
146
- * @api public
147
- */
148
-
149
- helpers.getObject = function(prop, context) {
150
- return utils.getObject(context, prop);
151
- };
152
-
153
- /**
154
- * Return true if `key` is an own, enumerable property
155
- * of the given `context` object.
156
- *
157
- * ```handlebars
158
- * {{hasOwn context key}}
159
- * ```
160
- *
161
- * @param {String} `key`
162
- * @param {Object} `context` The context object.
163
- * @return {Boolean}
164
- * @api public
165
- */
166
-
167
- helpers.hasOwn = function(context, key) {
168
- return hasOwn.call(context, key);
169
- };
170
-
171
- /**
172
- * Return true if `value` is an object.
173
- *
174
- * ```handlebars
175
- * {{isObject "foo"}}
176
- * //=> false
177
- * ```
178
- * @param {String} `value`
179
- * @return {Boolean}
180
- * @api public
181
- */
182
-
183
- helpers.isObject = function(value) {
184
- return utils.typeOf(value) === 'object';
185
- };
186
-
187
- /**
188
- * Parses the given string using `JSON.parse`.
189
- *
190
- * ```handlebars
191
- * <!-- string: '{"foo": "bar"}' -->
192
- * {{JSONparse string}}
193
- * <!-- results in: { foo: 'bar' } -->
194
- * ```
195
- * @param {String} `string` The string to parse
196
- * @contributor github.com/keeganstreet
197
- * @block
198
- * @api public
199
- */
200
-
201
- helpers.JSONparse = function(str, options) {
202
- return JSON.parse(str);
203
- };
204
-
205
- /**
206
- * Stringify an object using `JSON.stringify`.
207
- *
208
- * ```handlebars
209
- * <!-- object: { foo: 'bar' } -->
210
- * {{JSONstringify object}}
211
- * <!-- results in: '{"foo": "bar"}' -->
212
- * ```
213
- * @param {Object} `obj` Object to stringify
214
- * @return {String}
215
- * @api public
216
- */
217
-
218
- helpers.JSONstringify = function(obj, indent) {
219
- if (!utils.isNumber(indent)) {
220
- indent = 0;
221
- }
222
- return JSON.stringify(obj, null, indent);
223
- };
224
-
225
- /**
226
- * Deeply merge the properties of the given `objects` with the
227
- * context object.
228
- *
229
- * @param {Object} `object` The target object. Pass an empty object to shallow clone.
230
- * @param {Object} `objects`
231
- * @return {Object}
232
- * @api public
233
- */
234
-
235
- helpers.merge = function(context/*, objects, options*/) {
236
- var args = [].slice.call(arguments);
237
- var opts = {};
238
-
239
- if (util.isOptions(args[args.length - 1])) {
240
- // remove handlebars options object
241
- opts = args.pop().hash;
242
- // re-add options.hash
243
- args.push(opts);
244
- }
245
-
246
- return Object.assign.apply(null, args);
247
- };
248
-
249
- /**
250
- * Alias for parseJSON. this will be
251
- * deprecated in a future release
252
- */
253
-
254
- helpers.parseJSON = helpers.JSONparse;
255
-
256
- /**
257
- * Pick properties from the context object.
258
- *
259
- * @param {Array|String} `properties` One or more properties to pick.
260
- * @param {Object} `context`
261
- * @param {Object} `options` Handlebars options object.
262
- * @return {Object} Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.
263
- * @block
264
- * @api public
265
- */
266
-
267
- helpers.pick = function(props, context, options) {
268
- var keys = array.arrayify(props);
269
- var len = keys.length, i = -1;
270
- var result = {};
271
-
272
- while (++i < len) {
273
- result = helpers.extend({}, result, utils.getObject(context, keys[i]));
274
- }
275
-
276
- if (options.fn) {
277
- if (Object.keys(result).length) {
278
- return options.fn(result);
279
- }
280
- return options.inverse(context);
281
- }
282
- return result;
283
- };
284
-
285
- /**
286
- * Alias for JSONstringify. this will be
287
- * deprecated in a future release
288
- */
289
-
290
- helpers.stringify = helpers.JSONstringify;
package/lib/path.js DELETED
@@ -1,181 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('handlebars-utils');
4
- var path = require('path');
5
- var utils = require('./utils');
6
- var helpers = module.exports;
7
-
8
- utils.expectedType = (variableName, expectedType, variableValue) => {
9
- const actualType = Object.prototype.toString.call(variableValue).slice(8, -1).toLowerCase();
10
-
11
- if (actualType !== expectedType) {
12
- throw new TypeError(`Expected ${variableName} to be of type ${expectedType}, but got ${actualType}`);
13
- }
14
- };
15
-
16
-
17
- /**
18
- * Get the directory path segment from the given `filepath`.
19
- *
20
- * ```handlebars
21
- * {{absolute "docs/toc.md"}}
22
- * <!-- results in: 'docs' -->
23
- * ```
24
- * @param {String} `ext`
25
- * @return {String}
26
- * @api public
27
- */
28
-
29
- helpers.absolute = function(filepath, options) {
30
- options = options || {data: {}};
31
- var context = util.options(this, options);
32
- var ctx = Object.assign({}, options.data.root, context);
33
- var cwd = ctx.cwd || process.cwd();
34
- return path.resolve(cwd, filepath);
35
- };
36
-
37
- /**
38
- * Get the directory path segment from the given `filepath`.
39
- *
40
- * ```handlebars
41
- * {{dirname "docs/toc.md"}}
42
- * <!-- results in: 'docs' -->
43
- * ```
44
- * @param {String} `ext`
45
- * @return {String}
46
- * @api public
47
- */
48
-
49
- helpers.dirname = function(filepath, options) {
50
- if (typeof filepath !== 'string') {
51
- throw new TypeError(utils.expectedType('filepath', 'string', filepath));
52
- }
53
- return path.dirname(filepath);
54
- };
55
-
56
- /**
57
- * Get the relative filepath from `a` to `b`.
58
- *
59
- * ```handlebars
60
- * {{relative a b}}
61
- * ```
62
- * @param {String} `a`
63
- * @param {String} `b`
64
- * @return {String}
65
- * @api public
66
- */
67
-
68
- helpers.relative = function(a, b) {
69
- if (typeof a !== 'string') {
70
- throw new TypeError(utils.expectedType('first path', 'string', a));
71
- }
72
- if (typeof b !== 'string') {
73
- throw new TypeError(utils.expectedType('second path', 'string', b));
74
- }
75
- return utils.relative(a, b);
76
- };
77
-
78
- /**
79
- * Get the file extension from the given `filepath`.
80
- *
81
- * ```handlebars
82
- * {{basename "docs/toc.md"}}
83
- * <!-- results in: 'toc.md' -->
84
- * ```
85
- * @param {String} `ext`
86
- * @return {String}
87
- * @api public
88
- */
89
-
90
- helpers.basename = function(filepath) {
91
- if (typeof filepath !== 'string') {
92
- throw new TypeError(utils.expectedType('filepath', 'string', filepath));
93
- }
94
- return path.basename(filepath);
95
- };
96
-
97
- /**
98
- * Get the "stem" from the given `filepath`.
99
- *
100
- * ```handlebars
101
- * {{stem "docs/toc.md"}}
102
- * <!-- results in: 'toc' -->
103
- * ```
104
- * @param {String} `filepath`
105
- * @return {String}
106
- * @api public
107
- */
108
-
109
- helpers.stem = function(filepath) {
110
- if (typeof filepath !== 'string') {
111
- throw new TypeError(utils.expectedType('filepath', 'string', filepath));
112
- }
113
- return path.basename(filepath, path.extname(filepath));
114
- };
115
-
116
- /**
117
- * Get the file extension from the given `filepath`.
118
- *
119
- * ```handlebars
120
- * {{extname "docs/toc.md"}}
121
- * <!-- results in: '.md' -->
122
- * ```
123
- * @param {String} `filepath`
124
- * @return {String}
125
- * @api public
126
- */
127
-
128
- helpers.extname = function(filepath) {
129
- if (typeof filepath !== 'string') {
130
- throw new TypeError(utils.expectedType('filepath', 'string', filepath));
131
- }
132
- return path.extname(filepath);
133
- };
134
-
135
- /**
136
- * Resolve an absolute path from the given `filepath`.
137
- *
138
- * ```handlebars
139
- * {{resolve "docs/toc.md"}}
140
- * <!-- results in: '/User/dev/docs/toc.md' -->
141
- * ```
142
- * @param {String} `filepath`
143
- * @return {String}
144
- * @api public
145
- */
146
-
147
- helpers.resolve = function(filepath) {
148
- var args = [].slice.call(arguments);
149
- var opts = util.options(this, args.pop());
150
- var cwd = path.resolve(opts.cwd || process.cwd());
151
- args.unshift(cwd);
152
- return path.resolve.apply(path, args);
153
- };
154
-
155
- /**
156
- * Get specific (joined) segments of a file path by passing a
157
- * range of array indices.
158
- *
159
- * ```handlebars
160
- * {{segments "a/b/c/d" "2" "3"}}
161
- * <!-- results in: 'c/d' -->
162
- *
163
- * {{segments "a/b/c/d" "1" "3"}}
164
- * <!-- results in: 'b/c/d' -->
165
- *
166
- * {{segments "a/b/c/d" "1" "2"}}
167
- * <!-- results in: 'b/c' -->
168
- * ```
169
- *
170
- * @param {String} `filepath` The file path to split into segments.
171
- * @return {String} Returns a single, joined file path.
172
- * @api public
173
- */
174
-
175
- helpers.segments = function(filepath, a, b) {
176
- if (typeof filepath !== 'string') {
177
- throw new TypeError(utils.expectedType('filepath', 'string', filepath));
178
- }
179
- var segments = filepath.split(/[\\\/]+/);
180
- return segments.slice(a, b).join('/');
181
- };
package/lib/regex.js DELETED
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('handlebars-utils');
4
- var utils = require('./utils');
5
- var helpers = module.exports;
6
-
7
- /**
8
- * Convert the given string to a regular expression.
9
- *
10
- * ```handlebars
11
- * {{toRegex "foo"}}
12
- * <!-- results in: /foo/ -->
13
- * ```
14
- * @param {String} `str`
15
- * @return {RegExp}
16
- * @api public
17
- */
18
-
19
- helpers.toRegex = function(str, locals, options) {
20
- var opts = util.options({}, locals, options);
21
- return new RegExp(str, opts.flags);
22
- };
23
-
24
- /**
25
- * Returns true if the given `str` matches the given regex. A regex can
26
- * be passed on the context, or using the [toRegex](#toregex) helper as a
27
- * subexpression.
28
- *
29
- * ```handlebars
30
- * {{test "bar" (toRegex "foo")}}
31
- * <!-- results in: false -->
32
- * {{test "foobar" (toRegex "foo")}}
33
- * <!-- results in: true -->
34
- * {{test "foobar" (toRegex "^foo$")}}
35
- * <!-- results in: false -->
36
- * ```
37
- * @param {String} `str`
38
- * @return {RegExp}
39
- * @api public
40
- */
41
-
42
- helpers.test = function(str, regex) {
43
- if (!util.isString(str)) {
44
- return false;
45
- }
46
- if (utils.typeOf(regex) !== 'regexp') {
47
- throw new TypeError('expected a regular expression');
48
- }
49
- return regex.test(str);
50
- };