-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
44 lines (38 loc) · 1.14 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Service } from '@feathersjs/feathers';
import { trim } from 'lodash';
export function getServicePath(service: Service<any>, model: any) {
if (!service.name && !service.path && !model.servicePath) {
throw new Error(
`Service for model named ${String(model.name)} is missing a path or name property.`
);
}
return service.path || service.name || model.servicePath;
}
export function stripSlashes(location: string) {
return trim(location, '/')
}
export function getShortName(service: any) {
let namespace = stripSlashes(service);
if (Array.isArray(namespace)) {
namespace = namespace.slice(-1);
} else if (namespace.includes('/')) {
namespace = namespace.slice(namespace.lastIndexOf('/') + 1);
}
return namespace;
}
export function getNameFromPath(service: any) {
return stripSlashes(service);
}
export function ns(namespace: any, servicePath: any) {
if (namespace) {
return namespace;
}
return getNameFromPath(servicePath);
}
export function assignIfNotPresent(model: any, props: any): void {
for (const key in props) {
if (!(key in model)) {
model[key] = props[key];
}
}
}