This repository was archived by the owner on Oct 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathngParse.js
89 lines (74 loc) · 2.11 KB
/
ngParse.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* ngParse - utility for parsing ngDefine module definitions
*
* @version 1.1.0
* @author Nico Rehwaldt <http://github.com/Nikku>
*
* @license (c) 2013 Nico Rehwaldt, MIT
*/
define(function() {
var MODULE_DEPENDENCY = /^module:([^:]*)(:(.*))?$/;
var INTERNAL = /^ng/;
function isFunction(value){ return typeof value == 'function'; }
function isInternal(module) {
return INTERNAL.test(module);
}
function asFileDependency(module) {
return module.replace(/\./g, "/");
}
function toArray(arrayLike) {
return Array.prototype.slice.call(arrayLike, 0);
}
/**
* For each implementation as used by AngularJS
*/
function forEach(obj, iterator, context) {
var key;
if (obj) {
if (isFunction(obj)){
for (key in obj) {
if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key);
}
}
} else if (obj.forEach && obj.forEach !== forEach) {
obj.forEach(iterator, context);
} else if (isArrayLike(obj)) {
for (key = 0; key < obj.length; key++)
iterator.call(context, obj[key], key);
} else {
for (key in obj) {
if (obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key);
}
}
}
}
return obj;
}
function parseNgModule(name, dependencies) {
var files = [],
modules = [];
forEach(dependencies, function(d) {
var moduleMatch = d.match(MODULE_DEPENDENCY);
if (moduleMatch) {
var module = moduleMatch[1],
path = moduleMatch[3];
if (!path && !isInternal(module)) {
// infer path from module name
path = asFileDependency(module);
}
// add module dependency
modules.push(module);
if (path) {
// add path dependency if it exists
files.push(path);
}
} else {
files.push(d);
}
});
return { name: name, fileDependencies: files, moduleDependencies: modules };
}
return { parseNgModule: parseNgModule };
});