<commit_before>const isTrue = require('./isTrue')
const parseLength = require('./parseLength')

const transforms = {
  stroke: {
    type: 'boolean'
  },
  fill: {
    type: 'boolean'
  },
  textRepeat: {
    type: 'boolean'
  },
  textBelow: {
    type: 'boolean'
  },
  noClip: {
    type: 'boolean'
  },
  width: {
    rename: 'weight',
    type: 'length'
  },
  opacity: {
    type: 'float'
  },
  fillOpacity: {
    type: 'float'
  },
  offset: {
    type: 'length'
  }
}

function styleToLeaflet (style, twigData) {
  const ret = JSON.parse(JSON.stringify(style))

  for (let k in ret) {
    let value = ret[k]

    if (k in transforms) {
      const transform = transforms[k]

      switch (transform.type) {
        case 'boolean':
          value = isTrue(ret[k])
          break
        case 'float':
          value = parseFloat(ret[k])
          break
        case 'length':
          value = parseLength(ret[k], twigData.map.metersPerPixel)
          break<commit_msg>styleToLeaflet: bugfix, avoid error when twigdata or twigdata.map is not defined<commit_after>const isTrue = require('./isTrue')
const parseLength = require('./parseLength')

const transforms = {
  stroke: {
    type: 'boolean'
  },
  fill: {
    type: 'boolean'
  },
  textRepeat: {
    type: 'boolean'
  },
  textBelow: {
    type: 'boolean'
  },
  noClip: {
    type: 'boolean'
  },
  width: {
    rename: 'weight',
    type: 'length'
  },
  opacity: {
    type: 'float'
  },
  fillOpacity: {
    type: 'float'
  },
  offset: {
    type: 'length'
  }
}

function styleToLeaflet (style, twigData) {
  const ret = JSON.parse(JSON.stringify(style))

  for (let k in ret) {
    let value = ret[k]

    if (k in transforms) {
      const transform = transforms[k]

      switch (transform.type) {
        case 'boolean':
          value = isTrue(ret[k])
          break
        case 'float':
          value = parseFloat(ret[k])
          break
        case 'length':
          if (twigData && twigData.map) {
            value = parseLength(ret[k], twigData.map.metersPerPixel)
          } else {
            value = parseFloat(ret[k])
          }
          break
{'fraction_non_alphanumeric': 0.13859076061595893, 'fraction_numerical': 0.0, 'mean_word_length': 2.1390922401171304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7448524', 'n_tokens_mistral': 736, 'n_tokens_neox': 721, 'n_words': 169}