Giter Site home page Giter Site logo

core-hbs-helpers's People

Contributors

calebeby avatar erikjung avatar lyzadanger avatar neogeek avatar paul-hebert avatar renovate-bot avatar renovate[bot] avatar spaceninja avatar tylersticka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

kublaj sparkbox

core-hbs-helpers's Issues

dummyImgSrc missing from documentation

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.

toTitle helper is kinda confusing

⚠️ Note: I might just be a dummy.

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. ¯_(ツ)_/¯

Timestamp helper could be updated based on latest moment.js

The timestamp helper in this repo was written during a transitional time for Moment.js. It has a few quirks that could be corrected:

  • It uses Date.now() when Moment will default to the current date/time.
  • It uses Date.parse() instead of Moment's improved and highly customizable parsing.
  • It uses an isNaN check instead of Moment's stricter isValid method (which could potentially be used to provide more helpful error messages via isValidAt).
  • It lacks the ability to activate UTC mode, which can come in very handy for timestamps that are formatted with timezone assumptions.
  • It specifies a defaultFormat, which is not really necessary (.format() will output just fine without any arguments).

Consider replacing "and" and "or" helpers with "all" and "any"

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

Dependency Dashboard

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.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-node v4
npm
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
nvm
.nvmrc
  • node 20

  • Check this box to trigger a request for Renovate to run again on this repository

Set up CI

Things to check on CI:

  • Run eslint, ensure there are no lint errors
  • Run prettier, ensure there aren't formatting changes

Also add "build passing" badge

ESnext?

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.

toFraction should not require triple-slash

The toFraction helper currently requires a triple-slash to avoid encoding the already-encoded fraction special characters:

{{toFraction "1.25"}} // => 1&amp;#188;
{{{toFraction "1.25"}}} // => 1&#188;

I can see one of the following solutions working instead (in order of my preference):

  1. Appending the unicode characters themselves for Handlebars to escape.
  2. Returning the result as a Handlebars.safeString (more info)

"randomIf" is a potentially confusing name

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?

{{#randomBool}}This{{else}}That{{/randomBool}}
{{#trueOrFalse}}This{{else}}That{{/trueOrFalse}}
{{#maybe}}This{{else}}That{{/maybe}}

SVG helper fails a test

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)

Add placeholder img helper

Almost all of our prototyping projects benefit from a placeholder image solution, but most have caveats:

  • Placeholder images we save to project asset folders have to be created and managed manually.
  • Services like placehold.it or PlaceIMG require external requests, which can hang if connections are slow.
  • Client-side solutions like Holder.js require JavaScript, which can be a little tricky to integrate if the project includes both production and documentation-related JavaScript toolkits.

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:

  • Rewrite as a module within this repo
  • Write tests for it

Nit: Our use of function.name might be unnecessary

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

Add Tests

This repo needs tests to validate that everything is working as intended when upgrades happen.

Which helpers do we want here?

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.

Comments are needed

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 Renovate

All our public tools like this should have a tool installed to make sure we're keeping up-to-date with security patches.

  • add renovate
  • add renovate badge

Rename for npm publish

  • Update package.json name: @cloudfour/hbs-helpers.
  • npm version to create new version and tag
  • npm publish
  • Rename this repo to "hbs-helpers".
  • Update package.json repository: cloudfour/hbs-helpers.
  • [Maybe] Update package.json cloudfour/core-hbs-helpers.git# endpoints on older projects.

/CC @tylersticka @mrgerardorodriguez

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.