time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (3052B)


      1 
      2 {{alias}}( path[, options], predicate, clbk )
      3     Asynchronously resolves a path according to a predicate function by walking
      4     parent directories.
      5 
      6     When invoked, the predicate function is provided two arguments:
      7 
      8     - `path`: a resolved path
      9     - `next`: a callback to be invoked after processing a resolved path
     10 
     11     The `next` callback takes two arguments:
     12 
     13     - `error`: error argument
     14     - `result`: test result
     15 
     16     If a provided predicate function calls the `next` callback with a truthy
     17     `error` argument, the function suspends execution and immediately calls the
     18     `done` callback for subsequent `error` handling.
     19 
     20     The function immediately returns upon encountering a non-falsy `result`
     21     value and calls the `done` callback with `null` as the first argument and
     22     the resolved path as the second argument.
     23 
     24     If unable to resolve a path, the function returns `null` as the path result.
     25 
     26     Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
     27     wrap the `done` callback in a function which either executes at the end of
     28     the current stack (e.g., `nextTick`) or during a subsequent turn of the
     29     event loop (e.g., `setImmediate`, `setTimeout`).
     30 
     31     Parameters
     32     ----------
     33     path: string
     34         Path to resolve.
     35 
     36     options: Object (optional)
     37         Options.
     38 
     39     options.dir: string (optional)
     40         Base directory from which to search. Default: current working directory.
     41 
     42     predicate: Function
     43         The test function to invoke for each resolved path.
     44 
     45     clbk: Function
     46         Callback to invoke after resolving a path.
     47 
     48     Examples
     49     --------
     50     > function predicate( path, next ) {
     51     ...     setTimeout( onTimeout, path );
     52     ...     function onTimeout() {
     53     ...         console.log( path );
     54     ...         next( null, false );
     55     ...     }
     56     ... };
     57     > function onPath( error, path ) {
     58     ...     if ( error ) {
     59     ...         console.error( error.message );
     60     ...     } else {
     61     ...         console.log( path );
     62     ...     }
     63     ... };
     64     > {{alias}}( 'package.json', predicate, onPath );
     65 
     66 
     67 {{alias}}.sync( path[, options], predicate )
     68     Synchronously resolves a path according to a predicate function by walking
     69     parent directories.
     70 
     71     The predicate function is provided one argument:
     72 
     73     - `path`: a resolved path
     74 
     75     The function immediately returns upon encountering a truthy return value.
     76 
     77     If unable to resolve a path, the function returns `null` as the path result.
     78 
     79     Parameters
     80     ----------
     81     path: string
     82         Path to resolve.
     83 
     84     options: Object (optional)
     85         Options.
     86 
     87     options.dir: string (optional)
     88         Base directory from which to search. Default: current working directory.
     89 
     90     predicate: Function
     91         The test function to invoke for each resolved path.
     92 
     93     Returns
     94     -------
     95     out: string|null
     96         Resolved path.
     97 
     98     Examples
     99     --------
    100     > function predicate() { return false; };
    101     > var out = {{alias}}.sync( 'package.json', predicate );
    102 
    103     See Also
    104     --------
    105