Package Exports
- chunk-string-array
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chunk-string-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Chunk
Chunks a string array based on string length.
Installation
$ npm install chunk-string-arrayUsage
var chunk = require( 'chunk-string-array' );chunk( arr, length[, options ] );
Chunks a string array based on string length. The array elements are split into subarrays according to a length parameter, which specifies a combined length of all subarray elements.
var out = chunk( ['abc', 'de', 'fg', 'h', 'ijkl' ], 3 );
/*
[
['abc'],
['de'],
['fg','h'],
['ijkl']
]
*/The function accepts the following options:
* strict: boolean indicating whether the length criterion should be strictly enforced; i.e., no combined subarray length should exceed the criterion. Such a condition can occur when a single string exceeds the length. Setting this option to true ensures that all strings must be less than or equal to the length value. Default: false.
To strictly enforce a maximum subarray length, set the strict option to true.
var out = chunk( ['abc', 'de', 'fg', 'h', 'ijkl' ], 3, {
'strict': true
});
// => throws ErrorNotes
- The
functionsplitsarrayelements atomically; i.e., subarrays do not contain partialstringelements.
Examples
var mnames = require( 'datasets-male-first-names-en' );
var fnames = require( 'datasets-female-first-names-en' );
var shuffle = require( 'compute-shuffle' );
var chunk = require( 'chunk-string-array' );
// Create random groups of people under the constraint that the sum of all first names of people within a group cannot exceed 40 characters...
var maxLength = 40;
var names = mnames.concat( fnames );
shuffle( names );
var groups = chunk( names, maxLength );
for ( var i = 0; i < groups.length; i++ ) {
console.log( groups[ i ].join( ',' ) );
}To run the example code from the top-level application directory,
$ node ./examples/index.jsTests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make testAll new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covBrowser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsersTo view the tests in a local web browser,
$ make view-browser-testsLicense
Copyright
Copyright © 2016. Athan Reines.