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

ecamp / hal-json-vuex / 13321877237

13 Feb 2025 10:43PM UTC coverage: 84.708%. Remained the same
13321877237

push

github

web-flow
Update babel monorepo to v7.26.8

159 of 206 branches covered (77.18%)

Branch coverage included in aggregate %.

262 of 291 relevant lines covered (90.03%)

740.07 hits per line

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

100.0
/src/normalizeUri.js
1
/**
2
 * Sorts the query parameters in a URI, keeping the values of duplicate keys in order.
3
 * Example:
4
 * sortQueryParams('localhost/api/camps?q=something&dup=true&alpha=0&dup=false')
5
 * // 'localhost/api/camps?alpha=0&dup=true&dup=false&q=something'
6
 * @param uri      to be processed
7
 * @returns string URI with sorted query parameters
8
 */
9
function sortQueryParams (uri) {
10
  const queryStart = uri.indexOf('?')
3,039✔
11
  if (queryStart === -1) return uri
3,039✔
12

13
  const prefix = uri.substring(0, queryStart)
129✔
14
  const query = new URLSearchParams(uri.substring(queryStart + 1))
129✔
15
  const modifiedQuery = new URLSearchParams();
129✔
16

17
  [...new Set(query.keys())].sort().forEach((key) => {
129✔
18
    query.getAll(key).forEach((value) => {
234✔
19
      modifiedQuery.append(key, value)
243✔
20
    })
21
  })
22

23
  if ([...modifiedQuery.keys()].length) {
129✔
24
    return `${prefix}?${modifiedQuery.toString()}`
117✔
25
  }
26
  return prefix
12✔
27
}
28

29
/**
30
 * Extracts the URI from an entity (or uses the passed URI if it is a string) and normalizes it for use in
31
 * the Vuex store.
32
 * @param uriOrEntity     entity or literal URI string
33
 * @param baseUrl         common URI prefix to remove during normalization
34
 * @returns {null|string} normalized URI, or null if the uriOrEntity argument was not understood
35
 */
36
export function normalizeEntityUri (uriOrEntity, baseUrl = '') {
66✔
37
  if (uriOrEntity === undefined) return normalizeUri('', baseUrl)
3,060✔
38
  if (typeof uriOrEntity === 'string') return normalizeUri(uriOrEntity, baseUrl)
3,057✔
39
  return normalizeUri(((uriOrEntity || {})._meta || {}).self, baseUrl)
171✔
40
}
41

42
/**
43
 * Normalize a URI by sorting the query parameters and removing a given prefix.
44
 * @param uri             to be normalized
45
 * @param baseUrl         prefix to remove from the beginning of the URI if present
46
 * @returns {null|string} normalized URI, or null if uri is not a string
47
 */
48
function normalizeUri (uri, baseUrl) {
49
  if (typeof uri !== 'string') return null
3,060✔
50
  return sortQueryParams(uri).replace(new RegExp(`^${baseUrl}`), '')
3,039✔
51
}
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

© 2026 Coveralls, Inc