cloudfour / core-hbs-helpers Goto Github PK
View Code? Open in Web Editor NEWHandlebars helpers that we usually need
License: MIT License
Handlebars helpers that we usually need
License: MIT License
On the doxdox site, the documentation for dummyImgSrc
is missing. I just checked, and it's the only one that's not showing up. I'm not sure why, since there's what appears to be a properly formatted docblock in the code.
But I never remember that toTitle
only strips off numeric prefixes and nothing else.
For some reason I always assume it will do this. Which isn't even a common need now that there are capitalize helpers.
Now that Drizzle doesn't rely on filename prefixes, it could be that we don't even need this helper. ¯_(ツ)_/¯
Currently, some do and some don't. I think it's worthwhile to make all helpers that are unfriendly to type-ambiguous arguments throw exceptions when inoperable input is passed in.
Per the discussion in #1, we should figure out a way to simplify these.
The timestamp
helper in this repo was written during a transitional time for Moment.js. It has a few quirks that could be corrected:
Date.now()
when Moment will default to the current date/time.Date.parse()
instead of Moment's improved and highly customizable parsing.isNaN
check instead of Moment's stricter isValid
method (which could potentially be used to provide more helpful error messages via isValidAt
).defaultFormat
, which is not really necessary (.format()
will output just fine without any arguments).We should use eslint in this repo.
We currently have and
and or
helpers, which support two arguments.
It would be nice if instead we had helpers that resolved to true if all or any arguments resolve to true. This would work for two or more arguments.
Example helpers from a personal project:
var R = require('ramda');
function all () {
var options = R.last(arguments);
var result = true;
var values;
var i;
if (R.isNil(options.fn)) {
options = undefined;
values = arguments;
} else {
values = R.dropLast(1, arguments);
}
for (i = 0; i < values.length; i++) {
if (!values[i]) {
result = false;
break;
}
}
if (options) {
return result ? options.fn(this) : options.inverse(this);
}
return result;
};
function any () {
var options = R.last(arguments);
var values, result;
if (R.isNil(options.fn)) {
options = undefined;
values = arguments;
} else {
values = R.dropLast(1, arguments);
}
result = R.any(R.__, values);
if (options) {
return result ? options.fn(this) : options.inverse(this);
}
return result;
};
This project would be a good fit for https://doxdox.org
We can just output to README.md
as Markdown.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
.github/workflows/ci.yml
actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
actions/setup-node v4
package.json
capitalize ^2.0.0
chance ^1.0.3
handlebars ^4.0.3
ltx ^3.0.0
moment ^2.10.6
num2fraction ^1.2.2
ramda ^0.29.0
require-dir ^1.0.0
tinycolor2 ^1.3.0
tap-spec 5.0.0
tape 5.7.5
.nvmrc
node 20
Things to check on CI:
Also add "build passing" badge
I've been totally spoiled by our other repos. In particular, I think Handlebars helpers would benefit a lot from the new parameter stuff.
But, I understand the value of keeping these things lean as well. There could be performance issues or something similar. I'd consider this a low priority nicety.
Per discussion in #1, we should consistently rename all helpers that translate and return their input value:
For example:
The toFraction
helper currently requires a triple-slash to avoid encoding the already-encoded fraction special characters:
I can see one of the following solutions working instead (in order of my preference):
Handlebars.safeString
(more info)According to GitHub, the license info is "typically named LICENSE or LICENSE.txt." Not sure why ours has the .md
extension. ¯_(ツ)_/¯
We have the HBS helpers published on NPM. Perhaps we should show in the README to install from there instead?
https://www.npmjs.com/package/@cloudfour/hbs-helpers
This:
npm install --save-dev @cloudfour/hbs-helpers
Instead of this:
npm install --save-dev cloudfour/core-hbs-helpers.git
The {{randomIf}}
helper behavior is to render the fn
or inverse
block at random. IMO, the inclusion of "if" in the name implies that there is some kind of conditional logic.
Would a different name be clearer?
The svg
helper has a failing test. 🌮
✖ Errors when path is not an SVG
---------------------------------
operator: throws
expected: |-
'/only supports SVG files\\.$/'
actual: |-
{ [Error: Incomplete document] message: 'Incomplete document' }
at: Test.<anonymous> (/Users/erikjung/Projects/cloudfour/core-hbs-helpers/test/svg.spec.js:59:8)
timestamp
2016-05-16T18:12:09Z
/path/to/repo/core-hbs-helpers/test/timestamp.spec.js:20
test.ok(template().match(iso8601).length > 0, 'Works');
^
TypeError: Cannot read property 'length' of null
moment.js
introduced recent changes that cause one of our tests to fail. The suggested action to take is to loosen up the regular expression used in the timestamp
test.
Almost all of our prototyping projects benefit from a placeholder image solution, but most have caveats:
I prototyped a solution that uses a Handlebars helper to generate an SVG based on the provided attributes, encoding it as a data-uri
for use in templates. You can see the working prototype here: http://codepen.io/tylersticka/pen/7119ac1f7900118fae7cd5eab2f6e2fa/left?editors=1010
The prototype is tested and working in the latest versions of Safari (desktop + iOS), Chrome and Firefox, as well as IE 10 and up. Tasks remaining:
@mrgerardorodriguez asked a good question in this thread:
For my own curiosity, how is
capitalize.name
resolving to the proper name?
I didn't have an answer, but here is @erikjung's response (source):
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
But now that you mention it, it's kind of silly to use name on a reference that happens to be using the same value as its own identifier. It would make more sense if we were doing this:
const helper = require('path/to/helper'); Handlebars.registerHelper(helper.name, helper);
This repo needs tests to validate that everything is working as intended when upgrades happen.
This is the lowest of low priorities, but I read these examples first, and then spent a few minutes wondering why my usage of {{placeholder}}
wasn't working: https://github.com/cloudfour/core-hbs-helpers/blob/master/lib/dummyImgSrc.js#L62-L68
{{defaultTo something fallback}}
is one of my favorite helpers. While writing up cloudfour/drizzle-builder#82, I wondered if it might make sense to accept one or more arguments, returning the first one that evaluates truthy?
Example:
{{defaultTo something somethingElse "okay, fine"}}
Currently, we have: https://github.com/cloudfour/core-hbs-helpers/tree/master/lib
├── average.js
├── displayName.js
├── fraction.js *
├── ifAnd.js
├── ifEqual.js
├── ifOr.js
├── random.js
├── randomIf.js
├── slug.js *
├── timestamp.js *
└── toFixed.js *
* renamed from original version
I'm not sure that all of these are useful enough to maintain here, so I welcome others to discuss and decide. Also, there is some room for improvement regarding consistency. For example, some helpers assume more than others about the arguments passed to them, some throw errors, etc. We should make them all appear to have been written by the same person.
Per discussion in #1, we should include comments in order to document each helper.
Format:
/**
* This is a helper that helps something.
*
* @since v0.1.0
* @param {String} str
* @return {String}
* @see (if applicable)
* @example
*
* {{toSlug "Some String"}} //=> "some-string"
*/
Add badge for our NPM package
If you view this package on NPM, you'll notice it can't get to the README.
Unable to find a readme for @cloudfour/[email protected]
We should figure out why. 🤔
All our public tools like this should have a tool installed to make sure we're keeping up-to-date with security patches.
name: @cloudfour/hbs-helpers
.npm version
to create new version and tagnpm publish
repository: cloudfour/hbs-helpers
.cloudfour/core-hbs-helpers.git#
endpoints on older projects./CC @tylersticka @mrgerardorodriguez
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.