<commit_before># d3-helpers

> Little utility D3 functions

[![NPM][d3-helpers-icon] ][d3-helpers-url]

[![Build status][d3-helpers-ci-image] ][d3-helpers-ci-url]
[![dependencies][d3-helpers-dependencies-image] ][d3-helpers-dependencies-url]
[![devdependencies][d3-helpers-devdependencies-image] ][d3-helpers-devdependencies-url]

Install and use under Node:

```
npm install d3-helpers --save
var helpers = require('d3-helpers');
```

Install and use in browser using bower:

```
bower install d3-helpers
<script src="bower_components/d3-helpers/index.js"></script>
// attaches as window.d3h object
```

## Api

Helpers object is a function augmented by other tiny functions. First the *d3h* function itself<commit_msg>added example to readme<commit_after># d3-helpers

> Little utility D3 functions

[![NPM][d3-helpers-icon] ][d3-helpers-url]

[![Build status][d3-helpers-ci-image] ][d3-helpers-ci-url]
[![dependencies][d3-helpers-dependencies-image] ][d3-helpers-dependencies-url]
[![devdependencies][d3-helpers-devdependencies-image] ][d3-helpers-devdependencies-url]

Install and use under Node:

```
npm install d3-helpers --save
var d3h = require('d3-helpers');
```

Install and use in browser using bower:

```
bower install d3-helpers
<script src="bower_components/d3-helpers/index.js"></script>
// attaches as window.d3h object
```

## Example

D3 code before

```js
// x and y are scale functions
var line = d3.svg.line()
  .x(function (d) { return x(new Date(d.date)); })
  .y(function (d) { return y(+d.y); });
```

This is very common D3 callback code. Here is the same code with callbacks refactored
to use *d3-helpers*

```js
var line = d3.svg.line()
  .x(d3h('date', d3h.newDate, x))
  .y(d3h('y', Number, y));
```

Notice several benefits:

1. The `.x` callback is easier to read from left to right:
grab property *date*, then call *d3h.newDate* function on it, the call *x* function.
No more inside out composition flow as in `x(new Date(d.date))`
2. Mixing property names and functions to apply makes the author's intention clear.
`+d.y` is always ambiguous: did the author forget to add something or was this the
intention? Writing `d3h('y', Number, ...)` makes it explicit.
3. By eliminating writing each callback function, we eliminate potential sources of errors.
In addition, since every function passed as argument is external, they becoming testable.

## Api

**d3-helpers** is a [well-tested](test/helpers.spec.js) function
augmented by other tiny functions. First the *d3h* function itself
{'fraction_non_alphanumeric': 0.14177918983320095, 'fraction_numerical': 0.018665607625099286, 'mean_word_length': 4.738041002277904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1101643', 'n_tokens_mistral': 865, 'n_tokens_neox': 861, 'n_words': 270}