| 206 | } |
| 207 | |
| 208 | function getSmartSplit(dottedPath) { |
| 209 | const split = dottedPath.split('.') |
| 210 | const bits = [] |
| 211 | for (let i = 0, len = split.length; i < len; i++) { |
| 212 | const bit = split[i] |
| 213 | if (i === len - 1) { |
| 214 | bits.push(bit) |
| 215 | } else { |
| 216 | const next = split[i + 1] |
| 217 | if (/\d$/.test(bit) && /^\d/.test(next)) { |
| 218 | bits.push([bit, next].join('.')) |
| 219 | i++ // jump ahead one position in the loop |
| 220 | } else { |
| 221 | bits.push(bit) |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | return bits |
| 226 | } |
| 227 | |
| 228 | // The reason this is memoized, even though the parent caller function |
| 229 | // (`getDataByLanguage`) is also memoized is because we might read |