Completed
Push — master ( d7c134...17f83b )
by Taavo-Taur
54s
created

src/utils.js   A

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 51
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
nc 1
dl 0
loc 51
cc 0
rs 10
noi 0
wmc 7
mnd 1
bc 6
fnc 4
bpm 1.5
cpm 1.75

4 Functions

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ noop 0 2 1
A utils.js ➔ warn 0 6 3
A utils.js ➔ isNumericIDLike 0 3 1
A utils.js ➔ pick 0 7 2
1
import * as feathersUtil from 'feathers-commons/lib/utils'
2
3
export const each = feathersUtil.each
4
export const some = feathersUtil._.some
5
6
/**
7
 * Empty function
8
 */
9
export function noop() {
10
}
11
12
/**
13
 * Log debug in user's console
14
 *
15
 * @param args
16
 */
17
export function warn(...args) {
18
	/* istanbul ignore next */
19
	if (console || window.console) {
20
		console.warn('[vue-syncers-feathers]', ...args)
21
	}
22
}
23
24
const numberRegex = /^\d+$/
25
26
/**
27
 * Test if a value seems like a number
28
 *
29
 * @param value
30
 * @returns {boolean}
31
 */
32
33
export function isNumericIDLike(value) {
34
	return (typeof value !== 'number' && numberRegex.test(value))
35
}
36
37
/**
38
 * Return object with only selected keys
39
 *
40
 * @from https://github.com/feathersjs/feathers-memory
41
 * @param source
42
 * @param keys
43
 * @returns {object}
44
 */
45
export function pick(source, ...keys) {
46
	const result = {}
47
	for (let key of keys) {
48
		result[key] = source[key]
49
	}
50
	return result
51
}
52