@jaredwray/fumanchu 1.0.0

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/url.js ADDED
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ var url = require('url');
4
+ var util = require('handlebars-utils');
5
+ var querystring = require('querystring');
6
+ var helpers = module.exports;
7
+
8
+ /**
9
+ * Encodes a Uniform Resource Identifier (URI) component
10
+ * by replacing each instance of certain characters by
11
+ * one, two, three, or four escape sequences representing
12
+ * the UTF-8 encoding of the character.
13
+ *
14
+ * @param {String} `str` The un-encoded string
15
+ * @return {String} The endcoded string
16
+ * @api public
17
+ */
18
+
19
+ helpers.encodeURI = function(str) {
20
+ if (util.isString(str)) {
21
+ return encodeURIComponent(str);
22
+ }
23
+ };
24
+
25
+ /**
26
+ * Escape the given string by replacing characters with escape sequences.
27
+ * Useful for allowing the string to be used in a URL, etc.
28
+ *
29
+ * @param {String} `str`
30
+ * @return {String} Escaped string.
31
+ * @api public
32
+ */
33
+
34
+ helpers.escape = function(str) {
35
+ if (util.isString(str)) {
36
+ return querystring.escape(str);
37
+ }
38
+ };
39
+
40
+ /**
41
+ * Decode a Uniform Resource Identifier (URI) component.
42
+ *
43
+ * @param {String} `str`
44
+ * @return {String}
45
+ * @api public
46
+ */
47
+
48
+ helpers.decodeURI = function(str) {
49
+ if (util.isString(str)) {
50
+ return decodeURIComponent(str);
51
+ }
52
+ };
53
+
54
+ /**
55
+ * Alias for [encodeURI](#encodeuri).
56
+ * @api public
57
+ */
58
+
59
+ helpers.url_encode = function() {
60
+ return helpers.encodeURI.apply(this, arguments);
61
+ };
62
+
63
+ /**
64
+ * Alias for [decodeURI](#decodeuri).
65
+ * @api public
66
+ */
67
+
68
+ helpers.url_decode = function(val) {
69
+ return helpers.decodeURI.apply(this, arguments);
70
+ };
71
+
72
+ /**
73
+ * Take a base URL, and a href URL, and resolve them as a
74
+ * browser would for an anchor tag.
75
+ *
76
+ * @param {String} `base`
77
+ * @param {String} `href`
78
+ * @return {String}
79
+ * @api public
80
+ */
81
+
82
+ helpers.urlResolve = function(base, href) {
83
+ return url.resolve(base, href);
84
+ };
85
+
86
+ /**
87
+ * Parses a `url` string into an object.
88
+ *
89
+ * @param {String} `str` URL string
90
+ * @return {String} Returns stringified JSON
91
+ * @api public
92
+ */
93
+
94
+ helpers.urlParse = function(str) {
95
+ return url.parse(str);
96
+ };
97
+
98
+ /**
99
+ * Strip the query string from the given `url`.
100
+ *
101
+ * @param {String} `url`
102
+ * @return {String} the url without the queryString
103
+ * @api public
104
+ */
105
+
106
+ helpers.stripQuerystring = function(str) {
107
+ if (util.isString(str)) {
108
+ return str.split('?')[0];
109
+ }
110
+ };
111
+
112
+ /**
113
+ * Strip protocol from a `url`. Useful for displaying media that
114
+ * may have an 'http' protocol on secure connections.
115
+ *
116
+ * ```handlebars
117
+ * <!-- url = 'http://foo.bar' -->
118
+ * {{stripProtocol url}}
119
+ * <!-- results in: '//foo.bar' -->
120
+ * ```
121
+ * @param {String} `str`
122
+ * @return {String} the url with http protocol stripped
123
+ * @api public
124
+ */
125
+
126
+ helpers.stripProtocol = function(str) {
127
+ if (util.isString(str)) {
128
+ var parsed = url.parse(str);
129
+ parsed.protocol = '';
130
+ return parsed.format();
131
+ }
132
+ };
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+
3
+ var util = require('handlebars-utils');
4
+ var striptags = require('striptags');
5
+
6
+ /**
7
+ * Expose `utils`
8
+ */
9
+
10
+ var html = module.exports;
11
+
12
+ /**
13
+ * Remove extra newlines from HTML, respect indentation.
14
+ *
15
+ * @param {String} html
16
+ * @return {String}
17
+ * @api public
18
+ */
19
+
20
+ html.condense = function(str) {
21
+ return str.replace(/(\r\n|\r|\n|\u2028|\u2029) {2,}/g, '\n');
22
+ };
23
+
24
+ /**
25
+ * Add a single newline above code comments in HTML
26
+ *
27
+ * @param {String} `html`
28
+ * @return {String}
29
+ * @api public
30
+ */
31
+
32
+ html.padcomments = function(str) {
33
+ return str.replace(/(\s*<!--)/g, '\n$1');
34
+ };
35
+
36
+ /**
37
+ * Parse HTML tag attributes from the `options.hash`.
38
+ *
39
+ * @param {Object} `hash` Helper options hash, e.g. `{foo: 'bar'}`
40
+ * @return {String} Stringified attributes, e.g. `foo="bar"`
41
+ * @api public
42
+ */
43
+
44
+ html.parseAttributes = function parseAttributes(hash) {
45
+ return Object.keys(hash).map(function(key) {
46
+ var val = String(hash[key]).replace(/^['"]|["']$/g, '');
47
+ return key + '="' + val + '"';
48
+ }).join(' ');
49
+ };
50
+
51
+ /**
52
+ * Strip HTML tags from a string, so that only the text nodes
53
+ * are preserved.
54
+ *
55
+ * ```handlebars
56
+ * {{sanitize "<span>foo</span>"}}
57
+ * //=> 'foo'
58
+ * ```
59
+ *
60
+ * @param {String} `str` The string of HTML to sanitize.
61
+ * @return {String}
62
+ * @api public
63
+ */
64
+
65
+ html.sanitize = function(str) {
66
+ if (!util.isString(str)) return '';
67
+ return striptags(str).trim();
68
+ };
69
+
70
+ html.toAttributes = function toAttributes(hash) {
71
+ var res = '';
72
+ var keys = Object.keys(hash);
73
+ for (var i = 0; i < keys.length; i++) {
74
+ var val = hash[keys[i]];
75
+ if (val === true) {
76
+ res += ' ' + keys[i];
77
+ } else {
78
+ res += ' ' + keys[i] + '="' + String(val) + '"';
79
+ }
80
+ }
81
+ return res;
82
+ };
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var util = require('handlebars-utils');
4
+ var utils = require('./utils');
5
+
6
+ /**
7
+ * Returns true if the given value contains the given
8
+ * `object`, optionally passing a starting index.
9
+ *
10
+ * @param {Array} val
11
+ * @param {Object} obj
12
+ * @param {Number} start
13
+ * @return {Boolean}
14
+ */
15
+
16
+ utils.contains = function(val, obj, start) {
17
+ if (val == null || obj == null || !utils.isNumber(val.length)) {
18
+ return false;
19
+ }
20
+ return val.indexOf(obj, start) !== -1;
21
+ };
22
+
23
+ /**
24
+ * Remove leading and trailing whitespace and non-word
25
+ * characters from the given string.
26
+ *
27
+ * @param {String} `str`
28
+ * @return {String}
29
+ */
30
+
31
+ utils.chop = function(str) {
32
+ if (!util.isString(str)) return '';
33
+ var re = /^[-_.\W\s]+|[-_.\W\s]+$/g;
34
+ return str.trim().replace(re, '');
35
+ };
36
+
37
+ /**
38
+ * Change casing on the given `string`, optionally
39
+ * passing a delimiter to use between words in the
40
+ * returned string.
41
+ *
42
+ * ```handlebars
43
+ * utils.changecase('fooBarBaz');
44
+ * //=> 'foo bar baz'
45
+ *
46
+ * utils.changecase('fooBarBaz' '-');
47
+ * //=> 'foo-bar-baz'
48
+ * ```
49
+ * @param {String} `string` The string to change.
50
+ * @return {String}
51
+ * @api public
52
+ */
53
+
54
+ utils.changecase = function(str, fn) {
55
+ if (!util.isString(str)) return '';
56
+ if (str.length === 1) {
57
+ return str.toLowerCase();
58
+ }
59
+
60
+ str = utils.chop(str).toLowerCase();
61
+ if (typeof fn !== 'function') {
62
+ fn = utils.identity;
63
+ }
64
+
65
+ var re = /[-_.\W\s]+(\w|$)/g;
66
+ return str.replace(re, function(_, ch) {
67
+ return fn(ch);
68
+ });
69
+ };
70
+
71
+ /**
72
+ * Generate a random number
73
+ *
74
+ * @param {Number} `min`
75
+ * @param {Number} `max`
76
+ * @return {Number}
77
+ * @api public
78
+ */
79
+
80
+ utils.random = function(min, max) {
81
+ return min + Math.floor(Math.random() * (max - min + 1));
82
+ };
83
+
84
+ /**
85
+ * Expose `utils`
86
+ */
87
+
88
+ module.exports = utils;
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ var utils = require('lazy-cache')(require);
4
+ var fn = require;
5
+ require = utils;
6
+
7
+ // Array utils
8
+ require('array-sort', 'sortBy');
9
+ require('arr-flatten', 'flatten');
10
+
11
+ // Html utils
12
+ require('to-gfm-code-block', 'block');
13
+ require('html-tag', 'tag');
14
+
15
+ // JavaScript language utils
16
+ require('kind-of', 'typeOf');
17
+
18
+ // matching utils
19
+ require('is-glob');
20
+ require('micromatch', 'mm');
21
+ require('falsey');
22
+
23
+ // Number utils
24
+ require('is-even');
25
+ require('is-number');
26
+
27
+ // Object utils
28
+ require('create-frame');
29
+ require('get-object');
30
+ require('get-value', 'get');
31
+ require('for-own');
32
+
33
+ // Path utils
34
+ require('relative');
35
+ require = fn;
36
+
37
+ /**
38
+ * Expose `utils`
39
+ */
40
+
41
+ module.exports = utils;
package/package.json ADDED
@@ -0,0 +1,159 @@
1
+ {
2
+ "name": "@jaredwray/fumanchu",
3
+ "description": "Handlebars + Helpers = Fumanchu",
4
+ "version": "1.0.0",
5
+ "homepage": "https://github.com/jaredwray/fumanchu",
6
+ "author": "Jared Wray (me@jaredwray.com)",
7
+ "contributors": [
8
+ "Adrián Mugnolo (https://github.com/xymbol)",
9
+ "Aleš Kotnik (www.draagle.com)",
10
+ "Ali Sheehan-Dare (https://github.com/alisd23)",
11
+ "Anders D. Johnson (https://andrz.me)",
12
+ "Arthur Cinader (http://github.com/acinader)",
13
+ "Brian Woodward (https://twitter.com/doowb)",
14
+ "Dan Dascalescu (http://dandascalescu.com)",
15
+ "Dan Gorby (https://plus.google.com/+GreenRaccoon23)",
16
+ "Dane Petersen (https://thegreatsunra.com)",
17
+ "Daniel Wabyick (https://github.com/dwabyick)",
18
+ "Dennis Borisevich (https://github.com/DenSpirit)",
19
+ "Foundy (http://foundy.io)",
20
+ "GONZO (https://github.com/why2pac)",
21
+ "GracefulLight (https://brendaniel.github.io)",
22
+ "Hariadi Hinta (http://www.hariadi.org)",
23
+ "James Tsuyuki (https://github.com/jtsuyuki)",
24
+ "Jan Stola (https://github.com/iamstolis)",
25
+ "Jason Bellamy (http://jasonbellamy.com)",
26
+ "Jeffrey Froom (http://jfroom.com)",
27
+ "Jocelyn Badgley (http://www.chipersoft.com)",
28
+ "Joey Baker (https://www.byjoeybaker.com)",
29
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
30
+ "Kevin Davis (kevindav.us)",
31
+ "Laurent Goderre (https://github.com/LaurentGoderre)",
32
+ "Liam Moat (http://www.liammoat.com)",
33
+ "Makoto Tateno (https://github.com/makotot)",
34
+ "Marie Hogebrandt (http://mariehogebrandt.se)",
35
+ "Mark Perkins (http://allmarkedup.com)",
36
+ "Martyn Rushton (http://swapnull.co.uk)",
37
+ "Max Albrecht (178.is)",
38
+ "Michael Sheedy (michaelsheedy.com)",
39
+ "Mikko Tapionlinna (http://mikko.tapionlinna.fi)",
40
+ "Nathan Jessen (http://nathanjessen.github.io)",
41
+ "Nathaniel Furniss (https://github.com/nlfurniss)",
42
+ "Oleg Orlov (https://github.com/efender)",
43
+ "Omesh (https://github.com/omeshp)",
44
+ "Patrick Burtchaell (https://pburtchaell.com)",
45
+ "Paul Welsh (paulwelsh.info)",
46
+ "Raymond Camden (https://www.raymondcamden.com)",
47
+ "Rob (https://github.com/robsilva)",
48
+ "Sam Tiffin (https://samtiffin.com)",
49
+ "Shannon Moeller (http://shannonmoeller.com)",
50
+ "Spud Hsu (http://spud.in)",
51
+ "Stephen Way (http://stephenway.net)",
52
+ "Thomas Jaggi (http://responsive.ch)",
53
+ "Tim Douglas (https://github.com/timdouglas)",
54
+ "(https://github.com/homersimpsons)",
55
+ "Jonathas Ribeiro (https://github.com/jonathas)",
56
+ "Jared Wray (https://github.com/jaredwray)"
57
+ ],
58
+ "repository": "jaredwray/fumanchu",
59
+ "bugs": {
60
+ "url": "https://github.com/jaredwray/fumanchu/issues"
61
+ },
62
+ "license": "MIT",
63
+ "files": [
64
+ "index.js",
65
+ "helpers.js",
66
+ "lib",
67
+ "dist",
68
+ "index.d.ts"
69
+ ],
70
+ "source": "index.js",
71
+ "main": "index.js",
72
+ "types": "index.d.ts",
73
+ "browser": "dist/fumanchu.min.js",
74
+ "engines": {
75
+ "node": ">=14"
76
+ },
77
+ "scripts": {
78
+ "test": "c8 mocha --reporter list",
79
+ "test:ci": "c8 --reporter=lcov mocha --reporter list",
80
+ "build": "parcel build --dist-dir dist",
81
+ "clean": "rm -rf node_modules && rm -rf dist && rm -rf .parcel-cache"
82
+ },
83
+ "dependencies": {
84
+ "arr-flatten": "^1.1.0",
85
+ "array-sort": "^1.0.0",
86
+ "create-frame": "^1.0.0",
87
+ "define-property": "^2.0.2",
88
+ "falsey": "^1.0.0",
89
+ "for-in": "^1.0.2",
90
+ "for-own": "^1.0.0",
91
+ "get-object": "^0.2.0",
92
+ "get-value": "^3.0.1",
93
+ "handlebars": "^4.7.8",
94
+ "handlebars-helper-create-frame": "^0.1.0",
95
+ "handlebars-utils": "^1.0.6",
96
+ "has-value": "^2.0.2",
97
+ "helper-date": "^1.0.1",
98
+ "helper-for-markdown": "^1.0.2",
99
+ "helper-md": "^0.2.2",
100
+ "html-tag": "^2.0.0",
101
+ "is-even": "^1.0.0",
102
+ "is-glob": "^4.0.3",
103
+ "is-number": "^7.0.0",
104
+ "kind-of": "^6.0.3",
105
+ "lazy-cache": "^2.0.2",
106
+ "logging-helpers": "^1.0.0",
107
+ "micromatch": "^4.0.5",
108
+ "relative": "^3.0.2",
109
+ "striptags": "^3.2.0",
110
+ "to-gfm-code-block": "^0.1.1",
111
+ "year": "^0.2.1"
112
+ },
113
+ "devDependencies": {
114
+ "@parcel/watcher": "^2.3.0",
115
+ "c8": "^8.0.1",
116
+ "chai": "^4.3.8",
117
+ "global-modules": "^2.0.0",
118
+ "mocha": "^10.2.0",
119
+ "parcel": "^2.9.3",
120
+ "template-helpers": "^1.0.1",
121
+ "templates": "^1.2.9"
122
+ },
123
+ "keywords": [
124
+ "array",
125
+ "assemble",
126
+ "collection",
127
+ "comparison",
128
+ "date",
129
+ "handlebars",
130
+ "helper",
131
+ "helpers",
132
+ "html",
133
+ "i18n",
134
+ "inflection",
135
+ "log",
136
+ "logging",
137
+ "markdown",
138
+ "math",
139
+ "number",
140
+ "object",
141
+ "path",
142
+ "repeat",
143
+ "string",
144
+ "template",
145
+ "time",
146
+ "url",
147
+ "util",
148
+ "utility"
149
+ ],
150
+ "browserslist": [
151
+ "last 1 version",
152
+ "> 1%",
153
+ "not dead"
154
+ ],
155
+ "targets": {
156
+ "main": false,
157
+ "types": false
158
+ }
159
+ }