l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

common.js (1177B)


      1 'use strict';
      2 
      3 
      4 function isNothing(subject) {
      5   return (typeof subject === 'undefined') || (subject === null);
      6 }
      7 
      8 
      9 function isObject(subject) {
     10   return (typeof subject === 'object') && (subject !== null);
     11 }
     12 
     13 
     14 function toArray(sequence) {
     15   if (Array.isArray(sequence)) return sequence;
     16   else if (isNothing(sequence)) return [];
     17 
     18   return [ sequence ];
     19 }
     20 
     21 
     22 function extend(target, source) {
     23   var index, length, key, sourceKeys;
     24 
     25   if (source) {
     26     sourceKeys = Object.keys(source);
     27 
     28     for (index = 0, length = sourceKeys.length; index < length; index += 1) {
     29       key = sourceKeys[index];
     30       target[key] = source[key];
     31     }
     32   }
     33 
     34   return target;
     35 }
     36 
     37 
     38 function repeat(string, count) {
     39   var result = '', cycle;
     40 
     41   for (cycle = 0; cycle < count; cycle += 1) {
     42     result += string;
     43   }
     44 
     45   return result;
     46 }
     47 
     48 
     49 function isNegativeZero(number) {
     50   return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
     51 }
     52 
     53 
     54 module.exports.isNothing      = isNothing;
     55 module.exports.isObject       = isObject;
     56 module.exports.toArray        = toArray;
     57 module.exports.repeat         = repeat;
     58 module.exports.isNegativeZero = isNegativeZero;
     59 module.exports.extend         = extend;