All files / shared unicodeStringJsonObjectListFixedLength.js

100% Statements 19/19
100% Branches 5/5
100% Functions 9/9
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 332x   2x 3200x 3200x 3200x   3200x 3200x   32324x   32324x   266158x 266158x                 35524x 292282x 292282x 2796571x 2796571x   292282x    
const {array, base64, integer, unicodeString} = require('fast-check')
 
module.exports = (blacklist, minLen = 1) => {
  return integer(minLen, 20).chain(len =>
    array(base64(), len, len).chain(keys => {
      const _keys = keys.map(skipChars(blacklist))
      
      return array(array(unicodeString(1, 20), len, len), minLen, 20).map(valuesList =>
        valuesList
        .map(values => {
          const _values = values.map(skipChars(blacklist))
          
          return (
            _keys
            .map((key, i) => ({[key + i]: _values[i]}))
            .reduce((acc, json) => Object.assign(acc, json), {})
          )
        })
      )
    })
  )
}
 
function skipChars (blacklist) {
  return string => {
    let str = ''
    for (let at = 0; at < string.length; at++) {
      const ch = string[at]
      if (blacklist.indexOf(ch) === -1) str += ch
    }
    return str || ' '
  }
}