• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TotalTechGeek / json-logic-engine / 12240508815

09 Dec 2024 05:01PM UTC coverage: 91.844% (-0.4%) from 92.254%
12240508815

Pull #38

github

web-flow
Merge dccdc6b3c into 91d18201d
Pull Request #38: Modified RFC6901

795 of 903 branches covered (88.04%)

Branch coverage included in aggregate %.

25 of 28 new or added lines in 2 files covered. (89.29%)

6 existing lines in 3 files now uncovered.

804 of 838 relevant lines covered (95.94%)

31664.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.43
/utilities/splitPath.js
1
const parsedPaths = new Map()
54✔
2

3
/**
4
 * Splits a path string into an array of parts; lightly memoized.
5
 * It will reset the entire cache after 2048 paths, this could be improved
6
 * by implementing an LRU cache or something, but I'm trying to keep
7
 * this library fairly dep free, and the code not too cumbersome.
8
 *
9
 * Memoizing the splitPath function can be seen as cheating, but I think it's likely
10
 * that a lot of the same paths will be used for logic, so it's a good optimization.
11
 *
12
 * @param {string} str
13
 * @returns {string[]}
14
 */
15
export function splitPathMemoized (str) {
16
  if (parsedPaths.has(str)) return parsedPaths.get(str)
26,640✔
17
  if (parsedPaths.size > 2048) parsedPaths.clear()
582!
18
  const parts = splitPath(str)
582✔
19
  parsedPaths.set(str, parts)
582✔
20
  return parts
582✔
21
}
22

23
const chars = ['~', '/', '.']
54✔
24

25
/**
26
 * Splits a path string into an array of parts.
27
 *
28
 *
29
 * @param {string} str
30
 * @param {string} separator
31
 * @returns {string[]}
32
 */
33
export function splitPath (str) {
34
  const parts = []
582✔
35
  let current = ''
582✔
36

37
  for (let i = 0; i < str.length; i++) {
582✔
38
    const char = str[i]
2,646✔
39
    if (char === '~') {
2,646✔
40
      if (str[i + 1] === '0' || str[i + 1] === '1' || str[i + 1] === '2') {
102!
41
        current += chars[+str[i + 1]]
102✔
42
        i++
102✔
NEW
43
      } else if (str[i + 1] === '~') {
×
NEW
44
        current += '~'
×
UNCOV
45
        i++
×
46
        // The following else might be something tweaked in a spec.
NEW
47
      } else throw new Error('Invalid escape sequence')
×
48
    } else if (char === '.' || char === '/') {
2,544✔
49
      if (i) parts.push(current)
270✔
50
      current = ''
270✔
51
    } else current += char
2,274✔
52
  }
53

54
  // The if prevents me from pushing more sections than characters
55
  // This is so that "." will [''] and not ['','']
56
  // But .h will be ['','.h']
57
  // .. becomes ['',''], ..h becomes ['', '', 'h']
58
  if (parts.length !== str.length) parts.push(current)
582!
59
  return parts
582✔
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc