Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace packages for its native version #12

Merged
merged 17 commits into from
Jan 10, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/helpers_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
workflow_dispatch:

jobs:
build:
build-and-test:

runs-on: ${{ matrix.os }}

Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

'use strict';

var forIn = require('for-in');
var define = require('define-property');
var lib = require('./lib/');

/**
Expand All @@ -25,16 +23,17 @@ 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) {
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;
Expand All @@ -43,16 +42,17 @@ module.exports = function helpers(groups, options) {
/**
* Expose helper groups
*/
for (const key in lib) {
const group = lib[key];

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;
});
});
};
}

/**
* Expose `utils`
Expand Down
8 changes: 6 additions & 2 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 '';
};
Expand Down
5 changes: 2 additions & 3 deletions lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down Expand Up @@ -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 `<script${attr ? ' ' + attr : ''}></script>`;
}

if (kindOf(context) === 'string') {
if (typeof context === 'string') {
return `<script src="${context}"></script>`;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ helpers.noop = function(options) {
* @api public
*/

helpers.typeOf = require('kind-of');
helpers.typeOf = function(val) { return typeof val; };

/**
* Block helper that builds the context for the block
Expand Down
3 changes: 1 addition & 2 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -184,7 +183,7 @@ helpers.hasOwn = function(context, key) {
*/

helpers.isObject = function(value) {
return kindOf(value) === 'object';
return typeof value === 'object';
};

/**
Expand Down
11 changes: 4 additions & 7 deletions lib/utils/createFrame.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
'use strict';

const define = require('define-property');
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;

define(frame, 'extend', function(data) {
extend(this, data);
});
frame.extend = function(data) {
Object.assign(this, data);
};

if (arguments.length > 1) {
var args = [].slice.call(arguments, 1);
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +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",
"get-object": "^0.2.0",
"get-value": "^3.0.1",
"handlebars": "^4.7.7",
Expand All @@ -100,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",
Expand Down
2 changes: 1 addition & 1 deletion test/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading