Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit c025e15

Browse files
committed
Fix formatting
1 parent dace42b commit c025e15

File tree

6 files changed

+119
-64
lines changed

6 files changed

+119
-64
lines changed

lib/defaults.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Default inflections
22
module.exports = function (inflect) {
3-
43
inflect.plural(/$/, 's');
54
inflect.plural(/s$/i, 's');
65
inflect.plural(/(ax|test)is$/i, '$1es');
@@ -64,5 +63,16 @@ module.exports = function (inflect) {
6463
inflect.irregular('safe', 'safes');
6564
inflect.irregular('fife', 'fifes');
6665

67-
inflect.uncountable(['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'sushi']);
68-
}
66+
inflect.uncountable([
67+
'equipment',
68+
'information',
69+
'rice',
70+
'money',
71+
'species',
72+
'series',
73+
'fish',
74+
'sheep',
75+
'jeans',
76+
'sushi',
77+
]);
78+
};

lib/inflect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ module.exports = function (attach) {
77
require('./native')(methods);
88
}
99

10-
return methods
10+
return methods;
1111
};

lib/inflections.js

+33-15
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,42 @@ Inflections.prototype.singular = function (rule, replacement) {
4949
//
5050
// irregular 'octopus', 'octopi'
5151
// irregular 'person', 'people'
52-
Inflections.prototype.irregular = function (singular, plural, fullMatchRequired) {
52+
Inflections.prototype.irregular = function (singular, plural, fullMatchRequired) {
5353
this.uncountables = util.array.del(this.uncountables, singular);
5454
this.uncountables = util.array.del(this.uncountables, plural);
55-
var prefix = "";
55+
var prefix = '';
5656
if (fullMatchRequired) {
57-
prefix = "^";
57+
prefix = '^';
5858
}
5959
if (singular[0].toUpperCase() == plural[0].toUpperCase()) {
60-
this.plural(new RegExp("(" + prefix + singular[0] + ")" + singular.slice(1) + "$", "i"), '$1' + plural.slice(1));
61-
this.plural(new RegExp("(" + prefix + plural[0] + ")" + plural.slice(1) + "$", "i"), '$1' + plural.slice(1));
62-
this.singular(new RegExp("(" + prefix + plural[0] + ")" + plural.slice(1) + "$", "i"), '$1' + singular.slice(1));
60+
this.plural(new RegExp('(' + prefix + singular[0] + ')' + singular.slice(1) + '$', 'i'), '$1' + plural.slice(1));
61+
this.plural(new RegExp('(' + prefix + plural[0] + ')' + plural.slice(1) + '$', 'i'), '$1' + plural.slice(1));
62+
this.singular(new RegExp('(' + prefix + plural[0] + ')' + plural.slice(1) + '$', 'i'), '$1' + singular.slice(1));
6363
} else {
64-
this.plural(new RegExp(prefix + (singular[0].toUpperCase()) + singular.slice(1) + "$"), plural[0].toUpperCase() + plural.slice(1));
65-
this.plural(new RegExp(prefix + (singular[0].toLowerCase()) + singular.slice(1) + "$"), plural[0].toLowerCase() + plural.slice(1));
66-
this.plural(new RegExp(prefix + (plural[0].toUpperCase()) + plural.slice(1) + "$"), plural[0].toUpperCase() + plural.slice(1));
67-
this.plural(new RegExp(prefix + (plural[0].toLowerCase()) + plural.slice(1) + "$"), plural[0].toLowerCase() + plural.slice(1));
68-
this.singular(new RegExp(prefix + (plural[0].toUpperCase()) + plural.slice(1) + "$"), singular[0].toUpperCase() + singular.slice(1));
69-
this.singular(new RegExp(prefix + (plural[0].toLowerCase()) + plural.slice(1) + "$"), singular[0].toLowerCase() + singular.slice(1));
64+
this.plural(
65+
new RegExp(prefix + singular[0].toUpperCase() + singular.slice(1) + '$'),
66+
plural[0].toUpperCase() + plural.slice(1)
67+
);
68+
this.plural(
69+
new RegExp(prefix + singular[0].toLowerCase() + singular.slice(1) + '$'),
70+
plural[0].toLowerCase() + plural.slice(1)
71+
);
72+
this.plural(
73+
new RegExp(prefix + plural[0].toUpperCase() + plural.slice(1) + '$'),
74+
plural[0].toUpperCase() + plural.slice(1)
75+
);
76+
this.plural(
77+
new RegExp(prefix + plural[0].toLowerCase() + plural.slice(1) + '$'),
78+
plural[0].toLowerCase() + plural.slice(1)
79+
);
80+
this.singular(
81+
new RegExp(prefix + plural[0].toUpperCase() + plural.slice(1) + '$'),
82+
singular[0].toUpperCase() + singular.slice(1)
83+
);
84+
this.singular(
85+
new RegExp(prefix + plural[0].toLowerCase() + plural.slice(1) + '$'),
86+
singular[0].toLowerCase() + singular.slice(1)
87+
);
7088
}
7189
};
7290

@@ -78,15 +96,15 @@ Inflections.prototype.irregular = function (singular, plural, fullMatchRequired
7896
// human "legacy_col_person_name", "Name"
7997
Inflections.prototype.human = function (rule, replacement) {
8098
this.humans.unshift([rule, replacement]);
81-
}
99+
};
82100

83101
// Add uncountable words that shouldn't be attempted inflected.
84102
//
85103
// uncountable "money"
86104
// uncountable ["money", "information"]
87105
Inflections.prototype.uncountable = function (words) {
88106
this.uncountables = this.uncountables.concat(words);
89-
}
107+
};
90108

91109
// Clears the loaded inflections within a given scope (default is _'all'_).
92110
// Give the scope as a symbol of the inflection type, the options are: _'plurals'_,
@@ -105,7 +123,7 @@ Inflections.prototype.clear = function (scope) {
105123
default:
106124
this[scope] = [];
107125
}
108-
}
126+
};
109127

110128
// Clears the loaded inflections and initializes them to [default](../inflections.html)
111129
Inflections.prototype.default = function () {

lib/methods.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var util = require('./util');
1010
var inflect = module.exports;
1111

1212
// Import [inflections](inflections.html) instance
13-
inflect.inflections = require('./inflections')
13+
inflect.inflections = require('./inflections');
1414

1515
// Gives easy access to add inflections to this class
1616
inflect.inflect = function (fn) {
@@ -31,13 +31,13 @@ inflect.inflect = function (fn) {
3131
// though there are cases where that does not hold:
3232
//
3333
// "SSLError".underscore.camelize // => "SslError"
34-
inflect.camelize = function(lower_case_and_underscored_word, first_letter_in_uppercase) {
34+
inflect.camelize = function (lower_case_and_underscored_word, first_letter_in_uppercase) {
3535
var result;
3636
if (first_letter_in_uppercase == null) first_letter_in_uppercase = true;
37-
result = util.string.gsub(lower_case_and_underscored_word, /\/(.?)/, function($) {
38-
return "." + (util.string.upcase($[1]));
37+
result = util.string.gsub(lower_case_and_underscored_word, /\/(.?)/, function ($) {
38+
return '.' + util.string.upcase($[1]);
3939
});
40-
result = util.string.gsub(result, /(?:_)(.)/, function($) {
40+
result = util.string.gsub(result, /(?:_)(.)/, function ($) {
4141
return util.string.upcase($[1]);
4242
});
4343
if (first_letter_in_uppercase) {
@@ -61,8 +61,8 @@ inflect.camelize = function(lower_case_and_underscored_word, first_letter_in_upp
6161
inflect.underscore = function (camel_cased_word) {
6262
var self;
6363
self = util.string.gsub(camel_cased_word, /\./, '/');
64-
self = util.string.gsub(self, /([A-Z]+)([A-Z][a-z])/, "$1_$2");
65-
self = util.string.gsub(self, /([a-z\d])([A-Z])/, "$1_$2");
64+
self = util.string.gsub(self, /([A-Z]+)([A-Z][a-z])/, '$1_$2');
65+
self = util.string.gsub(self, /([a-z\d])([A-Z])/, '$1_$2');
6666
self = util.string.gsub(self, /-/, '_');
6767
return self.toLowerCase();
6868
};
@@ -93,7 +93,9 @@ inflect.foreign_key = function (class_name, separate_class_name_and_id_with_unde
9393
if (separate_class_name_and_id_with_underscore == null) {
9494
separate_class_name_and_id_with_underscore = true;
9595
}
96-
return inflect.underscore(inflect.demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id");
96+
return (
97+
inflect.underscore(inflect.demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? '_id' : 'id')
98+
);
9799
};
98100

99101
// Turns a number into an ordinal string used to denote the position in an
@@ -109,17 +111,17 @@ inflect.ordinalize = function (number) {
109111
var _ref;
110112
number = parseInt(number);
111113
if ((_ref = Math.abs(number) % 100) === 11 || _ref === 12 || _ref === 13) {
112-
return "" + number + "th";
114+
return '' + number + 'th';
113115
} else {
114116
switch (Math.abs(number) % 10) {
115117
case 1:
116-
return "" + number + "st";
118+
return '' + number + 'st';
117119
case 2:
118-
return "" + number + "nd";
120+
return '' + number + 'nd';
119121
case 3:
120-
return "" + number + "rd";
122+
return '' + number + 'rd';
121123
default:
122-
return "" + number + "th";
124+
return '' + number + 'th';
123125
}
124126
}
125127
};
@@ -129,8 +131,8 @@ inflect.ordinalize = function (number) {
129131
// "money".uncountability() // => true
130132
// "my money".uncountability() // => true
131133
inflect.uncountability = function (word) {
132-
return inflect.inflections.uncountables.some(function(ele, ind, arr) {
133-
return word.match(new RegExp("(\\b|_)" + ele + "$", 'i')) != null;
134+
return inflect.inflections.uncountables.some(function (ele, ind, arr) {
135+
return word.match(new RegExp('(\\b|_)' + ele + '$', 'i')) != null;
134136
});
135137
};
136138

@@ -190,8 +192,8 @@ inflect.humanize = function (lower_case_and_underscored_word) {
190192
human = inflect.inflections.humans[i];
191193
result = util.string.gsub(result, human[0], human[1]);
192194
}
193-
result = util.string.gsub(result, /_id$/, "");
194-
result = util.string.gsub(result, /_/, " ");
195+
result = util.string.gsub(result, /_id$/, '');
196+
result = util.string.gsub(result, /_/, ' ');
195197
return util.string.capitalize(result, true);
196198
};
197199

@@ -229,4 +231,4 @@ inflect.tableize = function (class_name) {
229231
// "business".classify() // => "Busines"
230232
inflect.classify = function (table_name) {
231233
return inflect.camelize(inflect.singularize(util.string.gsub(table_name, /.*\./, '')));
232-
}
234+
};

lib/native.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
module.exports = function (obj) {
2-
32
var addProperty = function (method, func) {
43
String.prototype.__defineGetter__(method, func);
5-
}
4+
};
65

76
var stringPrototypeBlacklist = [
8-
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
9-
'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
10-
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
11-
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'gsub'
7+
'__defineGetter__',
8+
'__defineSetter__',
9+
'__lookupGetter__',
10+
'__lookupSetter__',
11+
'charAt',
12+
'constructor',
13+
'hasOwnProperty',
14+
'isPrototypeOf',
15+
'propertyIsEnumerable',
16+
'toLocaleString',
17+
'toString',
18+
'valueOf',
19+
'charCodeAt',
20+
'indexOf',
21+
'lastIndexof',
22+
'length',
23+
'localeCompare',
24+
'match',
25+
'replace',
26+
'search',
27+
'slice',
28+
'split',
29+
'substring',
30+
'toLocaleLowerCase',
31+
'toLocaleUpperCase',
32+
'toLowerCase',
33+
'toUpperCase',
34+
'trim',
35+
'trimLeft',
36+
'trimRight',
37+
'gsub',
1238
];
1339

1440
Object.keys(obj).forEach(function (key) {
@@ -22,5 +48,4 @@ module.exports = function (obj) {
2248
}
2349
}
2450
});
25-
26-
}
51+
};

lib/util.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Some utility functions in js
22

3-
var u = module.exports = {
3+
var u = (module.exports = {
44
array: {
55
// Returns a copy of the array with the value removed once
66
//
@@ -11,9 +11,9 @@ var u = module.exports = {
1111

1212
if (index != -1) {
1313
if (index == 0) {
14-
return arr.slice(1)
14+
return arr.slice(1);
1515
} else {
16-
return arr.slice(0, index).concat(arr.slice(index+1));
16+
return arr.slice(0, index).concat(arr.slice(index + 1));
1717
}
1818
} else {
1919
return arr;
@@ -23,16 +23,16 @@ var u = module.exports = {
2323
// Returns the first element of the array
2424
//
2525
// [1, 2, 3].first() #=> 1
26-
first: function(arr) {
26+
first: function (arr) {
2727
return arr[0];
2828
},
2929

3030
// Returns the last element of the array
3131
//
3232
// [1, 2, 3].last() #=> 3
33-
last: function(arr) {
34-
return arr[arr.length-1];
35-
}
33+
last: function (arr) {
34+
return arr[arr.length - 1];
35+
},
3636
},
3737
string: {
3838
// Returns a copy of str with all occurrences of pattern replaced with either replacement or the return value of a function.
@@ -52,7 +52,7 @@ var u = module.exports = {
5252
//
5353
gsub: function (str, pattern, replacement) {
5454
var i, match, matchCmpr, matchCmprPrev, replacementStr, result, self;
55-
if (!((pattern != null) && (replacement != null))) return u.string.value(str);
55+
if (!(pattern != null && replacement != null)) return u.string.value(str);
5656
result = '';
5757
self = str;
5858
while (self.length > 0) {
@@ -72,7 +72,7 @@ var u = module.exports = {
7272
replacementStr = replacement;
7373
for (i = 1; i <= 9; i++) {
7474
if (matchCmpr[i]) {
75-
replacementStr = u.string.gsub(replacementStr, new RegExp("\\\$" + i), matchCmpr[i]);
75+
replacementStr = u.string.gsub(replacementStr, new RegExp('\\$' + i), matchCmpr[i]);
7676
}
7777
}
7878
result += replacementStr;
@@ -91,13 +91,13 @@ var u = module.exports = {
9191
// Returns a copy of the String with the first letter being upper case
9292
//
9393
// "hello".upcase #=> "Hello"
94-
upcase: function(str) {
94+
upcase: function (str) {
9595
var self = u.string.gsub(str, /_([a-z])/, function ($) {
96-
return "_" + $[1].toUpperCase();
96+
return '_' + $[1].toUpperCase();
9797
});
9898

9999
self = u.string.gsub(self, /\/([a-z])/, function ($) {
100-
return "/" + $[1].toUpperCase();
100+
return '/' + $[1].toUpperCase();
101101
});
102102

103103
return self[0].toUpperCase() + self.substr(1);
@@ -115,7 +115,7 @@ var u = module.exports = {
115115

116116
if (!spaces) {
117117
self = u.string.gsub(self, /\s([a-z])/, function ($) {
118-
return " " + $[1].toUpperCase();
118+
return ' ' + $[1].toUpperCase();
119119
});
120120
}
121121

@@ -125,13 +125,13 @@ var u = module.exports = {
125125
// Returns a copy of the String with the first letter being lower case
126126
//
127127
// "HELLO".downcase #=> "hELLO"
128-
downcase: function(str) {
128+
downcase: function (str) {
129129
var self = u.string.gsub(str, /_([A-Z])/, function ($) {
130-
return "_" + $[1].toLowerCase();
130+
return '_' + $[1].toLowerCase();
131131
});
132132

133133
self = u.string.gsub(self, /\/([A-Z])/, function ($) {
134-
return "/" + $[1].toLowerCase();
134+
return '/' + $[1].toLowerCase();
135135
});
136136

137137
return self[0].toLowerCase() + self.substr(1);
@@ -142,6 +142,6 @@ var u = module.exports = {
142142
// "hello".value() #=> "hello"
143143
value: function (str) {
144144
return str.substr(0);
145-
}
146-
}
147-
}
145+
},
146+
},
147+
});

0 commit comments

Comments
 (0)