@sjcrh/proteinpaint-shared 2.147.1 → 2.149.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.147.1",
3
+ "version": "2.149.0",
4
4
  "description": "ProteinPaint code that is shared between server and client-side workspaces",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/joinUrl.js CHANGED
@@ -1,13 +1,13 @@
1
1
  function joinUrl(p1, ...p2) {
2
- if (typeof p1 != 'string') throw `first argument must be string type`
3
- if (!p1) throw 'blank string not allowed'
4
- if (p1.indexOf('?') != -1) throw 'search string not allowed'
2
+ if (typeof p1 != "string") throw `first argument must be string type`
3
+ if (!p1) throw "blank string not allowed"
4
+ if (p1.indexOf("?") != -1) throw "search string not allowed"
5
5
  let url = p1
6
6
  for (const p of p2) {
7
- if (typeof p != 'string') throw `all arguments must be string type`
8
- if (!p) throw 'blank string not allowed'
9
- if (url.slice(-1) != '/') url += '/'
10
- url += p.startsWith('/') ? p.substring(1) : p
7
+ if (typeof p != "string") throw `all arguments must be string type`
8
+ if (!p) throw "blank string not allowed"
9
+ if (url.slice(-1) != "/") url += "/"
10
+ url += p.startsWith("/") ? p.substring(1) : p
11
11
  }
12
12
  return url
13
13
  }
@@ -267,6 +267,8 @@ export function get_bin_label(bin, binconfig, valueConversion) {
267
267
  /*
268
268
  Generate a numeric bin label given a bin configuration and an optional term valueConversion object
269
269
  */
270
+ if ('label' in bin) return bin.label
271
+
270
272
  const bc = binconfig
271
273
  if (!bc.binLabelFormatter) bc.binLabelFormatter = getNumDecimalsFormatter(bc)
272
274
  if (!bin.startunbounded && !bin.stopunbounded && !('startinclusive' in bin) && !('stopinclusive' in bin)) {
@@ -6,7 +6,7 @@ Initialize a bin configuration for a numeric dataset
6
6
  {format: 'string'}: output bin config as JSON string
7
7
  */
8
8
  export default function initBinConfig(data, opts = {}) {
9
- if (data.find(d => !Number.isFinite(d))) throw 'non-numeric values found'
9
+ if (data.find(d => !Number.isFinite(d))) throw new Error('non-numeric values found')
10
10
 
11
11
  let binConfig
12
12
  const s = new Set(data)
package/src/time.js CHANGED
@@ -1,15 +1,15 @@
1
1
  function formatElapsedTime(ms) {
2
- if (typeof ms !== 'number') {
3
- return 'Invalid time: not a number'
2
+ if (typeof ms !== "number") {
3
+ return "Invalid time: not a number"
4
4
  }
5
5
  if (isNaN(ms)) {
6
- return 'Invalid time: NaN'
6
+ return "Invalid time: NaN"
7
7
  }
8
8
  if (!isFinite(ms)) {
9
- return ms > 0 ? 'Infinite time' : '-Infinite time'
9
+ return ms > 0 ? "Infinite time" : "-Infinite time"
10
10
  }
11
11
  const absMs = Math.abs(ms)
12
- const sign = ms < 0 ? '-' : ''
12
+ const sign = ms < 0 ? "-" : ""
13
13
  if (absMs < 1e3) {
14
14
  return `${sign}${absMs}ms`
15
15
  } else if (absMs < 6e4) {
package/src/urljson.js CHANGED
@@ -1,29 +1,38 @@
1
- import { isNumeric } from './helpers.js'
2
- const reserved = ['false', 'true', 'null', 'undefined']
3
- const delimiters = ['"', '{', '[']
1
+ import { isNumeric } from "./helpers.js"
2
+ const reserved = ["false", "true", "null", "undefined"]
3
+ const delimiters = ['"', "{", "["]
4
4
  function encode(rawObject) {
5
5
  const params = []
6
6
  for (const [key, value] of Object.entries(rawObject)) {
7
- if (typeof value == 'string' && !isNumeric(value) && !reserved.includes(value) && !delimiters.includes(value[0])) {
7
+ if (
8
+ typeof value == "string" &&
9
+ !isNumeric(value) &&
10
+ !reserved.includes(value) &&
11
+ !delimiters.includes(value[0])
12
+ ) {
8
13
  params.push(`${key}=${encodeURIComponent(value)}`)
9
14
  } else if (value !== void 0) {
10
15
  params.push(`${key}=${encodeURIComponent(JSON.stringify(value))}`)
11
16
  }
12
17
  }
13
- return params.join('&')
18
+ return params.join("&")
14
19
  }
15
20
  function decode(query) {
16
21
  const encoding = query.encoding
17
22
  for (const [key, value] of Object.entries(query)) {
18
23
  if (
19
- encoding == 'json' ||
20
- value == 'null' || // not new, always been
21
- value == 'true' || // NEED TO FIND-REPLACE CODE THAT USES value == 'true'
22
- value == 'false' || // NEED TO FIND-REPLACE CODE THAT USES value == 'false'
24
+ encoding == "json" ||
25
+ value == "null" || // not new, always been
26
+ value == "true" || // NEED TO FIND-REPLACE CODE THAT USES value == 'true'
27
+ value == "false" || // NEED TO FIND-REPLACE CODE THAT USES value == 'false'
23
28
  isNumeric(value) || // NEED TO check
24
- (typeof value == 'string' && value.startsWith('"') && value.endsWith('"')) ||
25
- (typeof value == 'string' && value.startsWith('{') && value.endsWith('}')) ||
26
- (value.startsWith('[') && value.endsWith(']'))
29
+ (typeof value == "string" &&
30
+ value.startsWith('"') &&
31
+ value.endsWith('"')) ||
32
+ (typeof value == "string" &&
33
+ value.startsWith("{") &&
34
+ value.endsWith("}")) ||
35
+ (value.startsWith("[") && value.endsWith("]"))
27
36
  )
28
37
  query[key] = JSON.parse(value)
29
38
  }