-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
57 lines (52 loc) · 1.63 KB
/
utils.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
steal(
'can/observe'
).then(function () {
can.pluralize = function (str) {
var ch = str[str.length - 1];
if (ch == 's') {
return str + 'es';
}
else if (ch == 'y') {
return str.substr(0, str.length - 1) + 'ies';
}
else {
return str + 's';
}
};
can.singularize = function (str) {
if (/ies$/.test(str)) {
return str.substr(0, str.length - 3) + 'y';
}
else if (/s$/.test(str)) {
return str.substr(0, str.length - 1);
}
else return str;
};
can.classize = function (s, join) {
// this can be moved out ..
// used for getter setter
var parts = s.split(can.undHash),
i = 0;
for (; i < parts.length; i++) {
parts[i] = can.capitalize(parts[i]);
}
return parts.join(join || '');
};
can.isId = function (id) {
return typeof id == 'string' || typeof id == 'number';
};
can.forEachAssociation = function (associations, callback) {
if (associations) {
for (var assocType in associations) {
associations[assocType] = can.makeArray(associations[assocType]);
for (var i = 0; i < associations[assocType].length; ++i) {
var association = associations[assocType][i];
if (typeof association != 'object') {
association = associations[assocType][i] = {type: association}
}
callback(assocType, association);
}
}
}
}
});