-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathModule.ts
More file actions
58 lines (53 loc) · 1.77 KB
/
Module.ts
File metadata and controls
58 lines (53 loc) · 1.77 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Declaration } from '../declarations/Declaration';
import { Export } from '../exports/Export';
import { Import } from '../imports/Import';
import { Node } from '../Node';
import { Namespace } from './Namespace';
import { Resource } from './Resource';
/**
* TypeScript resource. Declaration of a typescript module (i.e. declare module "foobar").
*
* @export
* @class Module
* @implements {Resource}
* @implements {Node}
*/
export class Module implements Resource, Node {
public imports: Import[] = [];
public exports: Export[] = [];
public declarations: Declaration[] = [];
public resources: Resource[] = [];
public usages: string[] = [];
public get identifier(): string {
return this.name;
}
public get nonLocalUsages(): string[] {
return this.usages
.filter(usage =>
!this.declarations.some(o => o.name === usage) &&
!this.resources.some(o => (o instanceof Module || o instanceof Namespace) && o.name === usage))
.concat(
this.resources.reduce((all, cur) => all.concat(cur.nonLocalUsages), [] as string[]),
);
}
constructor(public name: string, public start: number, public end: number) { }
/**
* Function that calculates the alias name of a namespace.
* Removes all underlines and dashes and camelcases the name.
*
* @returns {string}
*
* @memberof Module
*/
public getNamespaceAlias(): string {
return this.name.split(/[-_]/).reduce(
(all, cur, idx) => {
if (idx === 0) {
return all + cur.toLowerCase();
}
return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase();
},
'',
);
}
}