dist/functions.js
function measureIndents(
string,
config = {
  preWork: [],
  perLine: [],
  postWork: [] },

whitespace = /[ \t]/)
{
  let regexp = new RegExp(`(^${whitespace.source}*)`);
  let strings;
  let indents;

  if (Array.isArray(string)) {
    string = string.join('\n');
  }

  string = cautiouslyApply(string, config.preWork, true, true);
  strings = string.split(/\r?\n/);
  indents = strings.map((s, i, a) => {
    let search;

    s = cautiouslyApply(s, config.perLine, true, false);

    search = regexp.exec(s);
    return search && search[1].length || 0;
  });

  return cautiouslyApply([strings, indents], config.postWork);
}
function measureIndents(
string,
config = {
  preWork: [],
  perLine: [],
  postWork: [] },

whitespace = /[ \t]/)
{
  let regexp = new RegExp(`(^${whitespace.source}*)`);
  let strings;
  let indents;

  if (Array.isArray(string)) {
    string = string.join('\n');
  }

  string = cautiouslyApply(string, config.preWork, true, true);
  strings = string.split(/\r?\n/);
  indents = strings.map((s, i, a) => {
    let search;

    s = cautiouslyApply(s, config.perLine, true, false);

    search = regexp.exec(s);
    return search && search[1].length || 0;
  });

  return cautiouslyApply([strings, indents], config.postWork);
}
function measureIndents ( string , config = { preWork : [ ] , perLine : [ ] , postWork : [ ] } , whitespace = / [ \t] / ) { let regexp = new RegExp ( ` ${ whitespace . source } ` ) ; let strings ; let indents ; if ( Array . isArray ( string ) ) { string = string . join ( '\n' ) ; } string = cautiouslyApply ( string , config . preWork , true , true ) ; strings = string . split ( / \r?\n / ) ; indents = strings . map ( ( s , i , a ) => { let search ; s = cautiouslyApply ( s , config . perLine , true , false ) ; search = regexp . exec ( s ) ; return search && search [ 1 ] . length || 0 ; } ) ; return cautiouslyApply ( [ strings , indents ] , config . postWork ) ; }
Measure indents is something that may be of use for any tag function. Its
purpose is to take a string, split it into separate lines and count the
leading whitespace of each line. Once finished, it returns an array of
two items; the list of strings and the matching list of indents which are
related to each other via index.

The function also receives a config object which allows you to specify up
to three lists worth of functions.

`preWork` is a list of functions that receive the following arguments in
each callback and are meant as a pluggable way to modify the initial string
programmatically by the consuming developer. Examples might be to prune
empty initial and final lines if they contain only whitespace

```
preWorkFn(string: string): string

- string: the supplied string to be modified by the function with the
new version to be used as the returned value. If null or undefined is
returned instead, the value supplied to the function will be used
```

`perLine` is list of functions that receive the following arguments in
each callback and are meant as a pluggable way to modify the line in
question. The expected return value is the newly modified string from which
to measure the indent of. Each item in the list will receive the modified
string returned by its predecessor. Effectively this is a map function

```
perLine(string: string, index: number, array: Array<string>): string
```

`postWork` is a list of functions that get called in order and receive
the final results in the form of an array containing two elements. The
first is the list of strings and the second is the list of measuredIndents.
The format of the supplied value (i.e. array of two arrays) is expected as
a return value. Failure to do so will likely end up as a bug someplace

```
postWork(
array: Array<Array<string>, Array<number>>
): Array<Array<string>, Array<number>>
```

All functions supplied to these arrays, if wrapped in an array with a
second parameter of true, will cause the function in question to be bound
with the item it is working on as the `this` context.

@param {string} string see above
@param {Object} config see above
@param {RegExp} whitespace the defintion for whitespaced used within
@return {Array<Array<string>, Array<number>>} an array containing two
arrays; the first being an array of one line per index and the second being
an index matched array of numbered offsets indicating the amount of white
space that line is prefixed with
Measure indents is something that may be of use for any tag function . Its purpose is to take a string split it into separate lines and count the leading whitespace of each line . Once finished it returns an array of two items ; the list of strings and the matching list of indents which are related to each other via index .