From 9c8ea54fb206e3f3e8a98c685f7bb4425084238b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jan 2024 13:24:07 +0100 Subject: [PATCH 01/16] Remove array-sort usage --- lib/array.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/array.js b/lib/array.js index ab4ce01a..8dcb8272 100644 --- a/lib/array.js +++ b/lib/array.js @@ -2,7 +2,6 @@ var util = require('handlebars-utils'); var helpers = module.exports; -const arraySort = require('array-sort'); const getValue = require('get-value'); const createFrame = require('./utils/createFrame'); @@ -642,7 +641,12 @@ helpers.sortBy = function(array, prop, options) { if (!util.isString(prop) && typeof prop !== 'function') { return array.sort(); } - return arraySort.apply(null, args); + + if (typeof prop === 'function') { + return array.sort(prop); + } + + return array.sort((a, b) => (a[prop] > b[prop] ? 1 : -1)); } return ''; }; From d980f9539bd628db5513228bcc0227d614f8c198 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jan 2024 13:34:20 +0100 Subject: [PATCH 02/16] Remove kind-of usage --- lib/html.js | 5 ++--- lib/misc.js | 2 +- lib/object.js | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/html.js b/lib/html.js index 291fed16..db23caf1 100644 --- a/lib/html.js +++ b/lib/html.js @@ -5,7 +5,6 @@ var util = require('handlebars-utils'); var html = require('./utils/html'); var parseAttr = html.parseAttributes; var helpers = module.exports; -const kindOf = require('kind-of'); const htmlTag = require('html-tag'); /** @@ -88,12 +87,12 @@ helpers.css = function(list, options) { */ helpers.js = function(context) { - if (kindOf(context) === 'object') { + if (typeof context === 'object' && context.hash) { var attr = parseAttr(context.hash); return ``; } - if (kindOf(context) === 'string') { + if (typeof context === 'string') { return ``; } diff --git a/lib/misc.js b/lib/misc.js index 906a932a..a132ef13 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -71,7 +71,7 @@ helpers.noop = function(options) { * @api public */ -helpers.typeOf = require('kind-of'); +helpers.typeOf = (val) => typeof val /** * Block helper that builds the context for the block diff --git a/lib/object.js b/lib/object.js index 32cbca40..97a79b84 100644 --- a/lib/object.js +++ b/lib/object.js @@ -5,7 +5,6 @@ var util = require('handlebars-utils'); var array = require('./array'); var helpers = module.exports; const getValue = require('get-value'); -const kindOf = require('kind-of'); const getObject = require('get-object'); const createFrame = require('./utils/createFrame'); @@ -184,7 +183,7 @@ helpers.hasOwn = function(context, key) { */ helpers.isObject = function(value) { - return kindOf(value) === 'object'; + return typeof value === 'object'; }; /** From 87673f539f6740d54faf655155c458bd49b360b4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 9 Jan 2024 16:33:26 +0100 Subject: [PATCH 03/16] Remove array-sort package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 220ef829..8ab93bef 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "clean": "./node_modules/.bin/rimraf .nyc_output" }, "dependencies": { - "array-sort": "^1.0.0", "define-property": "^2.0.2", "extend-shallow": "^3.0.2", "for-in": "^1.0.2", From 0a685a46a4ca11362b3401b3b8ae90e5e1572be7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:23:04 +0100 Subject: [PATCH 04/16] Remove define-property usages --- lib/utils/createFrame.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/utils/createFrame.js b/lib/utils/createFrame.js index 8792b526..0b78f703 100644 --- a/lib/utils/createFrame.js +++ b/lib/utils/createFrame.js @@ -1,19 +1,18 @@ 'use strict'; -const define = require('define-property'); const extend = require('extend-shallow'); module.exports = function createFrame(data) { - if (typeof(data) !== 'object') { + if (typeof (data) !== 'object') { throw new TypeError('createFrame expects data to be an object'); } var frame = extend({}, data); frame._parent = data; - define(frame, 'extend', function(data) { + frame.extend = function (data) { extend(this, data); - }); + }; if (arguments.length > 1) { var args = [].slice.call(arguments, 1); From cf69ff20d537422b0fa3deb5ce68d0c1a080cb69 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:32:29 +0100 Subject: [PATCH 05/16] Remove define-property usages --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 4ede8993..fdfc2857 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,6 @@ 'use strict'; var forIn = require('for-in'); -var define = require('define-property'); var lib = require('./lib/'); /** @@ -25,7 +24,7 @@ module.exports = function helpers(groups, options) { options = options || {}; var hbs = options.handlebars || options.hbs || require('handlebars'); - define(module.exports, 'handlebars', hbs); + module.exports.handlebars = hbs; if (groups) { groups.forEach(function(key) { @@ -45,13 +44,13 @@ module.exports = function helpers(groups, options) { */ forIn(lib, function(group, key) { - define(module.exports, key, function(options) { + module.exports[key] = function(options) { options = options || {}; var hbs = options.handlebars || options.hbs || require('handlebars'); - define(module.exports, 'handlebars', hbs); + module.exports.handlebars = hbs; hbs.registerHelper(group); return hbs.helpers; - }); + }; }); /** From d9a6a642f11eee13e61fca4a8512075d52b502f1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:32:35 +0100 Subject: [PATCH 06/16] Lint --- lib/utils/createFrame.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/createFrame.js b/lib/utils/createFrame.js index 0b78f703..aa3c3dbc 100644 --- a/lib/utils/createFrame.js +++ b/lib/utils/createFrame.js @@ -3,14 +3,14 @@ const extend = require('extend-shallow'); module.exports = function createFrame(data) { - if (typeof (data) !== 'object') { + if (typeof(data) !== 'object') { throw new TypeError('createFrame expects data to be an object'); } var frame = extend({}, data); frame._parent = data; - frame.extend = function (data) { + frame.extend = function(data) { extend(this, data); }; From e6ceb065c0964eeb26a6090a5904d8bf09b59f05 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:33:21 +0100 Subject: [PATCH 07/16] Remove define-property package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 8ab93bef..36507247 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "clean": "./node_modules/.bin/rimraf .nyc_output" }, "dependencies": { - "define-property": "^2.0.2", "extend-shallow": "^3.0.2", "for-in": "^1.0.2", "get-object": "^0.2.0", From d9b18bdaefbb265e2eefad7902017c613274464c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:40:59 +0100 Subject: [PATCH 08/16] Remove extend-shallow usages --- lib/utils/createFrame.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/utils/createFrame.js b/lib/utils/createFrame.js index aa3c3dbc..ba552b11 100644 --- a/lib/utils/createFrame.js +++ b/lib/utils/createFrame.js @@ -1,17 +1,15 @@ 'use strict'; -const extend = require('extend-shallow'); - module.exports = function createFrame(data) { if (typeof(data) !== 'object') { throw new TypeError('createFrame expects data to be an object'); } - var frame = extend({}, data); + var frame = Object.assign({}, data); frame._parent = data; frame.extend = function(data) { - extend(this, data); + Object.assign(this, data); }; if (arguments.length > 1) { From 1fea98473cd73cd7bd41065a48c04ef55a31b74f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:41:26 +0100 Subject: [PATCH 09/16] Remove extend-shallow package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 36507247..51cab525 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "clean": "./node_modules/.bin/rimraf .nyc_output" }, "dependencies": { - "extend-shallow": "^3.0.2", "for-in": "^1.0.2", "get-object": "^0.2.0", "get-value": "^3.0.1", From 282a2917c9a6f05074ac360991dfa825707e38c3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:46:42 +0100 Subject: [PATCH 10/16] Replace for-in usages in favour of native implementation --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index fdfc2857..265c1a6e 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,6 @@ 'use strict'; -var forIn = require('for-in'); var lib = require('./lib/'); /** @@ -31,9 +30,10 @@ module.exports = function helpers(groups, options) { hbs.registerHelper(lib[key]); }); } else { - forIn(lib, function(group, key) { + for (const key in lib) { + const group = lib[key]; hbs.registerHelper(group); - }); + } } return hbs.helpers; @@ -42,8 +42,9 @@ module.exports = function helpers(groups, options) { /** * Expose helper groups */ +for (const key in lib) { + const group = lib[key]; -forIn(lib, function(group, key) { module.exports[key] = function(options) { options = options || {}; var hbs = options.handlebars || options.hbs || require('handlebars'); @@ -51,7 +52,7 @@ forIn(lib, function(group, key) { hbs.registerHelper(group); return hbs.helpers; }; -}); +} /** * Expose `utils` From ed83eb46a5d0937796adc5ea8b64a5cc5dd22f1b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 09:47:03 +0100 Subject: [PATCH 11/16] Remove for-in package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 51cab525..425ec234 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ "clean": "./node_modules/.bin/rimraf .nyc_output" }, "dependencies": { - "for-in": "^1.0.2", "get-object": "^0.2.0", "get-value": "^3.0.1", "handlebars": "^4.7.7", From debd223bf220077a6850ce8f9a557f2090b3c725 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 10:13:09 +0100 Subject: [PATCH 12/16] Rename test --- test/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/path.js b/test/path.js index d2ae8145..e3d54b1c 100644 --- a/test/path.js +++ b/test/path.js @@ -34,7 +34,7 @@ describe('assemble', function() { var fn = hbs.compile('{{relative "dist/docs.html" "index.html"}}'); assert.equal(fn(), path.join('..', 'index.html')); }); - it('should return the relative path from file A to file B', function() { + it('should return the relative path from file A to folder B', function() { var fn = hbs.compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); assert.equal(fn(), path.join('..', '..', 'assets')); }); From 690b67b66f89177a582d4e63de4612e73c4969de Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 11:37:31 +0100 Subject: [PATCH 13/16] Rename ci --- .github/workflows/helpers_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/helpers_ci.yml b/.github/workflows/helpers_ci.yml index 44bdee00..339f8a1a 100644 --- a/.github/workflows/helpers_ci.yml +++ b/.github/workflows/helpers_ci.yml @@ -18,7 +18,7 @@ on: workflow_dispatch: jobs: - build: + build-and-test: runs-on: ${{ matrix.os }} From acc3a18bd8f0577e6ab17544e9cd2f98f3de2f58 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 11:55:26 +0100 Subject: [PATCH 14/16] Remove helper-coverage --- package.json | 1 - yarn.lock | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 425ec234..52e4b6c8 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,6 @@ "global-modules": "^2.0.0", "gulp": "^4.0.2", "gulp-unused": "^0.2.1", - "helper-coverage": "^0.1.3", "is-valid-app": "^0.3.0", "js-yaml": "^4.1.0", "markdown-link": "^0.1.1", diff --git a/yarn.lock b/yarn.lock index 44d30301..f0abf14a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3731,7 +3731,7 @@ helper-copyright@^2.1.2: update-copyright "^0.2.3" year "^0.2.1" -helper-coverage@^0.1.2, helper-coverage@^0.1.3: +helper-coverage@^0.1.2: version "0.1.3" resolved "https://registry.yarnpkg.com/helper-coverage/-/helper-coverage-0.1.3.tgz#9fb7b1acca68ef951e9bfa8a7b0f6dd12b128a4d" integrity sha1-n7exrMpo75Uem/qKew9t0SsSik0= From ce05df172aec84dad8e0b20cc41abf5cab289be0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 14:03:40 +0100 Subject: [PATCH 15/16] Remove es6 usages --- lib/misc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/misc.js b/lib/misc.js index a132ef13..faf709c9 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -71,7 +71,7 @@ helpers.noop = function(options) { * @api public */ -helpers.typeOf = (val) => typeof val +helpers.typeOf = function(val) { return typeof val } /** * Block helper that builds the context for the block From 054d8f5ccdd5d81a30f8eddf5d9f20ed29c46c82 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 10 Jan 2024 14:08:18 +0100 Subject: [PATCH 16/16] Lint --- lib/misc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/misc.js b/lib/misc.js index faf709c9..1fee16c6 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -71,7 +71,7 @@ helpers.noop = function(options) { * @api public */ -helpers.typeOf = function(val) { return typeof val } +helpers.typeOf = function(val) { return typeof val; }; /** * Block helper that builds the context for the block