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

TotalTechGeek / json-logic-engine / 12225897151

08 Dec 2024 10:42PM UTC coverage: 91.489% (-0.8%) from 92.254%
12225897151

Pull #38

github

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

792 of 901 branches covered (87.9%)

Branch coverage included in aggregate %.

24 of 27 new or added lines in 2 files covered. (88.89%)

6 existing lines in 3 files now uncovered.

799 of 838 relevant lines covered (95.35%)

31649.37 hits per line

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

81.82
/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,448✔
17
  if (parsedPaths.size > 2048) parsedPaths.clear()
570!
18
  const parts = splitPath(str)
570✔
19
  parsedPaths.set(str, parts)
570✔
20
  return parts
570✔
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 = []
570✔
35
  let current = ''
570✔
36

37
  for (let i = 0; i < str.length; i++) {
570✔
38
    const char = str[i]
2,484✔
39
    if (char === '~') {
2,484✔
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,382✔
49
      parts.push(current)
228✔
50
      current = ''
228✔
51
    } else current += char
2,154✔
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)
570✔
59
  return parts
570✔
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