"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/asynckit/lib/state.js" (8 Mar 2017, 941 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // API
    2 module.exports = state;
    3 
    4 /**
    5  * Creates initial state object
    6  * for iteration over list
    7  *
    8  * @param   {array|object} list - list to iterate over
    9  * @param   {function|null} sortMethod - function to use for keys sort,
   10  *                                     or `null` to keep them as is
   11  * @returns {object} - initial state object
   12  */
   13 function state(list, sortMethod)
   14 {
   15   var isNamedList = !Array.isArray(list)
   16     , initState =
   17     {
   18       index    : 0,
   19       keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
   20       jobs     : {},
   21       results  : isNamedList ? {} : [],
   22       size     : isNamedList ? Object.keys(list).length : list.length
   23     }
   24     ;
   25 
   26   if (sortMethod)
   27   {
   28     // sort array keys based on it's values
   29     // sort object's keys just on own merit
   30     initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
   31     {
   32       return sortMethod(list[a], list[b]);
   33     });
   34   }
   35 
   36   return initState;
   37 }