index.js (1727B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 /** 22 * Generate a frequency table according to an indicator function. 23 * 24 * @module @stdlib/utils/async/tabulate-by 25 * 26 * @example 27 * var readFile = require( '@stdlib/fs/read-file' ); 28 * var tabulateByAsync = require( '@stdlib/utils/async/tabulate-by' ); 29 * 30 * var files = [ 31 * './beep.js', 32 * './boop.js' 33 * ]; 34 * 35 * function done( error, result ) { 36 * if ( error ) { 37 * throw error; 38 * } 39 * console.log( result ); 40 * } 41 * 42 * function indicator( file, next ) { 43 * var opts = { 44 * 'encoding': 'utf8' 45 * }; 46 * readFile( file, opts, onFile ); 47 * 48 * function onFile( error ) { 49 * if ( error ) { 50 * return next( null, 'nonreadable' ); 51 * } 52 * next( null, 'readable' ); 53 * } 54 * } 55 * 56 * tabulateByAsync( files, indicator, done ); 57 */ 58 59 // MODULES // 60 61 var setReadOnly = require( './../../../define-nonenumerable-read-only-property' ); 62 var tabulateByAsync = require( './tabulate_by.js' ); 63 var factory = require( './factory.js' ); 64 65 66 // MAIN // 67 68 setReadOnly( tabulateByAsync, 'factory', factory ); 69 70 71 // EXPORTS // 72 73 module.exports = tabulateByAsync;