alt159-rails 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/alt159-rails/version.rb +1 -1
- data/vendor/assets/javascripts/alt159/Cakefile +18 -0
- data/vendor/assets/javascripts/alt159/README.md +1 -0
- data/vendor/assets/javascripts/alt159/SpecRunner.html +56 -0
- data/vendor/assets/javascripts/alt159/index.html +196 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/MIT.LICENSE +20 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine-html.js +190 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine.css +166 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine.js +2476 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine_favicon.png +0 -0
- data/vendor/assets/javascripts/alt159/spec/DateSpec.js +11 -0
- data/vendor/assets/javascripts/alt159/spec/LagniappeSpec.js +49 -0
- data/vendor/assets/javascripts/alt159/spec/NumberSpec.js +79 -0
- data/vendor/assets/javascripts/alt159/spec/SpecHelper.js +2 -0
- data/vendor/assets/javascripts/alt159/spec/StringySpec.js +181 -0
- data/vendor/assets/javascripts/alt159/src/ALT159.coffee +39 -0
- data/vendor/assets/javascripts/alt159/src/ALT159.js +360 -0
- data/vendor/assets/javascripts/alt159/src/types/datey.coffee +1 -0
- data/vendor/assets/javascripts/alt159/src/types/langniappe.coffee +29 -0
- data/vendor/assets/javascripts/alt159/src/types/numbery.coffee +11 -0
- data/vendor/assets/javascripts/alt159/src/types/stringy.coffee +181 -0
- metadata +23 -3
@@ -0,0 +1,49 @@
|
|
1
|
+
describe("Lagniappe", function() {
|
2
|
+
|
3
|
+
//NOTE: must test before extending prototypes
|
4
|
+
describe("Chain",function(){
|
5
|
+
|
6
|
+
it("should equal the original", function(){
|
7
|
+
subject = f().chain( "stringTest", f.types.Stringy )
|
8
|
+
expect(subject === "stringTest").toBeTruthy();
|
9
|
+
});
|
10
|
+
|
11
|
+
it("should add functions", function(){
|
12
|
+
subject = f().chain( "stringTest", f.types.Stringy )
|
13
|
+
expect(subject.underscore !== void 0).toBeTruthy()
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should not alter the prototypes", function(){
|
17
|
+
subject = f().chain( "stringTest", f.types.Stringy )
|
18
|
+
expect(String.prototype.underscore === void 0).toBeTruthy()
|
19
|
+
});
|
20
|
+
|
21
|
+
//it("strings should be chanable", function(){
|
22
|
+
// subject = "stringTest";
|
23
|
+
// expect(subject.capitalize().underscore() ).toEqual("string_test");
|
24
|
+
// var new_string = "Im a new String";
|
25
|
+
// expect(new_string.underscore === void 0).toBeTruthy()
|
26
|
+
//});
|
27
|
+
|
28
|
+
});
|
29
|
+
|
30
|
+
|
31
|
+
//describe("extend prototypes",function(){
|
32
|
+
|
33
|
+
// beforeEach(function(){
|
34
|
+
// f().extendPrototypes();
|
35
|
+
// });
|
36
|
+
//
|
37
|
+
// it("should add capitalize to string", function(){
|
38
|
+
// subject = "string";
|
39
|
+
// expect(subject.capitalize() ).toEqual("String");
|
40
|
+
// });
|
41
|
+
|
42
|
+
// it("should work for numbery", function(){
|
43
|
+
// subject = 2;
|
44
|
+
// expect( subject.isEven() ).toBeTruthy();
|
45
|
+
// });
|
46
|
+
|
47
|
+
//});
|
48
|
+
|
49
|
+
});
|
@@ -0,0 +1,79 @@
|
|
1
|
+
describe("Number", function() {
|
2
|
+
|
3
|
+
describe("odd even", function() {
|
4
|
+
it("should not be odd ", function() {
|
5
|
+
expect(ALT159(2).isOdd()).toBeFalsy()
|
6
|
+
});
|
7
|
+
it("should be odd ", function() {
|
8
|
+
expect(ALT159(3).isOdd()).toBeTruthy()
|
9
|
+
});
|
10
|
+
it("should be even ", function() {
|
11
|
+
expect(ALT159(2).isEven()).toBeTruthy()
|
12
|
+
});
|
13
|
+
it("should not be even ", function() {
|
14
|
+
expect(ALT159(3).isEven()).toBeFalsy()
|
15
|
+
});
|
16
|
+
});
|
17
|
+
|
18
|
+
describe("money", function(){
|
19
|
+
it('should have good defaults', function(){
|
20
|
+
expect(ALT159("1234567.89").money()).toEqual("$1,234,567.89");
|
21
|
+
});
|
22
|
+
|
23
|
+
it('should accept a different "symbol" option', function(){
|
24
|
+
expect(ALT159("1234567.89").money({symbol: '#'})).toEqual("#1,234,567.89");
|
25
|
+
});
|
26
|
+
|
27
|
+
it('should accept a different "seperator" option', function(){
|
28
|
+
expect(ALT159("1234567.89").money({seperator: '_'})).toEqual("$1_234_567.89");
|
29
|
+
});
|
30
|
+
|
31
|
+
it('should accept a different "dot" option', function(){
|
32
|
+
expect(ALT159("1234567.89").money({dot: '*'})).toEqual("$1,234,567*89");
|
33
|
+
});
|
34
|
+
|
35
|
+
it('should accept a different "precision" option', function(){
|
36
|
+
expect(ALT159("1234567.89").money({precision: 1})).toEqual("$1,234,567.9");
|
37
|
+
});
|
38
|
+
|
39
|
+
it('should accept a different all at the same time option', function(){
|
40
|
+
var opts = {
|
41
|
+
precision: 1,
|
42
|
+
symbol: '@',
|
43
|
+
dot: '*',
|
44
|
+
seperator: '_'
|
45
|
+
}
|
46
|
+
|
47
|
+
expect(ALT159("1234567.89").money(opts)).toEqual("@1_234_567*9");
|
48
|
+
});
|
49
|
+
});
|
50
|
+
|
51
|
+
describe("number", function(){
|
52
|
+
it('should have good defaults', function(){
|
53
|
+
expect(ALT159("1234567.89").number()).toEqual("1,234,567.89");
|
54
|
+
});
|
55
|
+
|
56
|
+
it('should accept a different "seperator" option', function(){
|
57
|
+
expect(ALT159("1234567.89").number({seperator: '_'})).toEqual("1_234_567.89");
|
58
|
+
});
|
59
|
+
|
60
|
+
it('should accept a different "dot" option', function(){
|
61
|
+
expect(ALT159("1234567.89").number({dot: '*'})).toEqual("1,234,567*89");
|
62
|
+
});
|
63
|
+
|
64
|
+
it('should accept a different "precision" option', function(){
|
65
|
+
expect(ALT159("1234567.89").number({precision: 1})).toEqual("1,234,567.9");
|
66
|
+
});
|
67
|
+
|
68
|
+
it('should accept a different all at the same time option', function(){
|
69
|
+
var opts = {
|
70
|
+
precision: 1,
|
71
|
+
dot: '*',
|
72
|
+
seperator: '_'
|
73
|
+
}
|
74
|
+
|
75
|
+
expect(ALT159("1234567.89").number(opts)).toEqual("1_234_567*9");
|
76
|
+
});
|
77
|
+
});
|
78
|
+
|
79
|
+
});
|
@@ -0,0 +1,181 @@
|
|
1
|
+
describe("Stringy", function() {
|
2
|
+
|
3
|
+
describe("capitalize", function() {
|
4
|
+
|
5
|
+
it("should capitalize the stirng", function() {
|
6
|
+
subject = ALT159("i am a stringy").capitalize();
|
7
|
+
expect(subject).toEqual("I am a stringy");
|
8
|
+
});
|
9
|
+
|
10
|
+
it("should capitalize an empty stirng", function() {
|
11
|
+
subject = ALT159("").capitalize();
|
12
|
+
expect(subject).toEqual("");
|
13
|
+
});
|
14
|
+
|
15
|
+
});
|
16
|
+
|
17
|
+
|
18
|
+
describe("numbers", function() {
|
19
|
+
|
20
|
+
it("should return the numbers from the string", function() {
|
21
|
+
subject = ALT159("12345").numbers();
|
22
|
+
expect(subject).toEqual(12345);
|
23
|
+
});
|
24
|
+
|
25
|
+
it("should be able to handle decimals", function() {
|
26
|
+
subject = ALT159("12345.6").numbers();
|
27
|
+
expect(subject).toEqual(12345.6);
|
28
|
+
});
|
29
|
+
|
30
|
+
it("should remove random chars", function() {
|
31
|
+
subject = ALT159("1rand2om3ch4ars5").numbers();
|
32
|
+
expect(subject).toEqual(12345);
|
33
|
+
});
|
34
|
+
|
35
|
+
});
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
describe('underscore', function(){
|
40
|
+
|
41
|
+
it('underscores camelcase', function() {
|
42
|
+
subject = ALT159("CamelCase").underscore();
|
43
|
+
expect(subject).toEqual('camel_case');
|
44
|
+
});
|
45
|
+
|
46
|
+
it('underscores sentences', function() {
|
47
|
+
subject = ALT159("I am a sentence").underscore();
|
48
|
+
expect(subject).toEqual('i_am_a_sentence');
|
49
|
+
});
|
50
|
+
|
51
|
+
});
|
52
|
+
|
53
|
+
|
54
|
+
describe('camel', function(){
|
55
|
+
|
56
|
+
it('CamelCase CamelCase', function() {
|
57
|
+
subject = ALT159("CamelCase").camel();
|
58
|
+
expect(subject).toEqual('CamelCase');
|
59
|
+
});
|
60
|
+
|
61
|
+
it('CamelCase underscore', function() {
|
62
|
+
subject = ALT159("camel_case").camel();
|
63
|
+
expect(subject).toEqual('CamelCase');
|
64
|
+
});
|
65
|
+
|
66
|
+
it('underscores sentences', function() {
|
67
|
+
subject = ALT159("I am a sentence").camel();
|
68
|
+
expect(subject).toEqual('IAmASentence');
|
69
|
+
});
|
70
|
+
|
71
|
+
});
|
72
|
+
|
73
|
+
|
74
|
+
describe('humanize',function(){
|
75
|
+
|
76
|
+
it('humanizes underscored', function(){
|
77
|
+
subject = ALT159("snake_case").humanize();
|
78
|
+
expect(subject).toEqual('Snake case')
|
79
|
+
});
|
80
|
+
|
81
|
+
it('humanizes camelcase', function(){
|
82
|
+
subject = ALT159("CamelCase").humanize();
|
83
|
+
expect(subject).toEqual('Camel Case');
|
84
|
+
});
|
85
|
+
|
86
|
+
});
|
87
|
+
|
88
|
+
describe('pluralize',function(){
|
89
|
+
|
90
|
+
it('pluralize normal word', function(){
|
91
|
+
subject = ALT159("snake").pluralize();
|
92
|
+
expect(subject).toEqual('snakes')
|
93
|
+
});
|
94
|
+
|
95
|
+
it('pluralize work ending in s', function(){
|
96
|
+
subject = ALT159("class").pluralize();
|
97
|
+
expect(subject).toEqual('classes');
|
98
|
+
});
|
99
|
+
|
100
|
+
it('pluralize irregular words', function(){
|
101
|
+
subject = ALT159("cow").pluralize();
|
102
|
+
expect(subject).toEqual('kine');
|
103
|
+
});
|
104
|
+
|
105
|
+
it('pluralize uncountable words', function(){
|
106
|
+
subject = ALT159("rice").pluralize();
|
107
|
+
expect(subject).toEqual('rice');
|
108
|
+
});
|
109
|
+
|
110
|
+
});
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
describe('singularize',function(){
|
115
|
+
|
116
|
+
it('singularize normal word', function(){
|
117
|
+
subject = ALT159("snakes").singularize();
|
118
|
+
expect(subject).toEqual('snake')
|
119
|
+
});
|
120
|
+
|
121
|
+
it('singularize work ending in s', function(){
|
122
|
+
subject = ALT159("classes").singularize();
|
123
|
+
expect(subject).toEqual('class');
|
124
|
+
});
|
125
|
+
|
126
|
+
it('singularize irregular words', function(){
|
127
|
+
subject = ALT159("kine").singularize();
|
128
|
+
expect(subject).toEqual('cow');
|
129
|
+
});
|
130
|
+
|
131
|
+
it('singularize uncountable words', function(){
|
132
|
+
subject = ALT159("rice").singularize();
|
133
|
+
expect(subject).toEqual('rice');
|
134
|
+
});
|
135
|
+
|
136
|
+
});
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
describe('titleize',function(){
|
141
|
+
|
142
|
+
it('should capitalize all the words', function(){
|
143
|
+
subject = ALT159("all_the_words").titleize();
|
144
|
+
expect(subject).toEqual('All The Words')
|
145
|
+
});
|
146
|
+
|
147
|
+
it('should capitalize all the words', function(){
|
148
|
+
subject = ALT159("all the words").titleize();
|
149
|
+
expect(subject).toEqual('All The Words')
|
150
|
+
});
|
151
|
+
|
152
|
+
});
|
153
|
+
|
154
|
+
describe('truncate',function(){
|
155
|
+
it('should chop of extra bits', function(){
|
156
|
+
subject = ALT159("a long long string").truncate(7);
|
157
|
+
expect(subject).toEqual('a long ...')
|
158
|
+
});
|
159
|
+
it('should allow for different (extras)', function(){
|
160
|
+
subject = ALT159("a long long string").truncate(7, "");
|
161
|
+
expect(subject).toEqual('a long ')
|
162
|
+
});
|
163
|
+
});
|
164
|
+
|
165
|
+
|
166
|
+
describe('isBlank',function(){
|
167
|
+
it('should return true if empty', function(){
|
168
|
+
subject = ALT159("").isBlank();
|
169
|
+
expect(subject).toEqual(true)
|
170
|
+
});
|
171
|
+
it('should return true if spaces', function(){
|
172
|
+
subject = ALT159(" ").isBlank();
|
173
|
+
expect(subject).toEqual(true);
|
174
|
+
});
|
175
|
+
it('should return false if contains something', function(){
|
176
|
+
subject = ALT159(":P").isBlank();
|
177
|
+
expect(subject).toEqual(false);
|
178
|
+
});
|
179
|
+
});
|
180
|
+
|
181
|
+
});
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2012 Micah Woods
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
# of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
# so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
#ALT159 = \u0192 = f = (obj) -> AHHH helps
|
21
|
+
#stringy = require './stringy'
|
22
|
+
|
23
|
+
window.ALT159 = window.f = ((obj) ->
|
24
|
+
|
25
|
+
ALT159 = (obj) ->
|
26
|
+
return new Stringy(obj) if typeof obj is "string"
|
27
|
+
return new Numbery(obj) if toString.call(obj) is "[object Number]"
|
28
|
+
return new Datey(obj) if toString.call(obj) is "[object Date]"
|
29
|
+
return new Lagniappe() if obj is undefined
|
30
|
+
null
|
31
|
+
|
32
|
+
ALT159.types =
|
33
|
+
Stringy : Stringy
|
34
|
+
Numbery : Numbery
|
35
|
+
Datey : Datey
|
36
|
+
|
37
|
+
ALT159
|
38
|
+
)()
|
39
|
+
|
@@ -0,0 +1,360 @@
|
|
1
|
+
(function() {
|
2
|
+
var Datey, Lagniappe, Numbery, Stringy, inflect, rules;
|
3
|
+
|
4
|
+
Lagniappe = function() {};
|
5
|
+
|
6
|
+
Lagniappe.prototype = {
|
7
|
+
extendPrototypes: function() {
|
8
|
+
var addFunction, unnicer;
|
9
|
+
addFunction = function(obj, func, key) {
|
10
|
+
return obj.prototype[key] = function() {
|
11
|
+
return func.apply({
|
12
|
+
value: this
|
13
|
+
}, arguments);
|
14
|
+
};
|
15
|
+
};
|
16
|
+
unnicer = function(obj, to_add) {
|
17
|
+
var key, _results;
|
18
|
+
_results = [];
|
19
|
+
for (key in to_add.prototype) {
|
20
|
+
if (!obj.prototype[key]) {
|
21
|
+
_results.push(addFunction(obj, to_add.prototype[key], key));
|
22
|
+
} else {
|
23
|
+
_results.push(void 0);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
return _results;
|
27
|
+
};
|
28
|
+
unnicer(String, Stringy);
|
29
|
+
return unnicer(Number, Numbery);
|
30
|
+
},
|
31
|
+
chain: function(value, type) {
|
32
|
+
f().extendPrototypes();
|
33
|
+
return value;
|
34
|
+
},
|
35
|
+
reloadStylesheets: function() {
|
36
|
+
var i, links, queryString;
|
37
|
+
queryString = "?reload=" + new Date().getTime();
|
38
|
+
links = document.getElementsByTagName("link");
|
39
|
+
i = 0;
|
40
|
+
while (i < links.length) {
|
41
|
+
if (links[i] && links[i].ref === "stylesheet") {
|
42
|
+
links[i].href = links[i].href.replace(/\?.*|$/, queryString);
|
43
|
+
}
|
44
|
+
i++;
|
45
|
+
}
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
Numbery = function(val) {
|
51
|
+
return this.value = val;
|
52
|
+
};
|
53
|
+
|
54
|
+
Numbery.prototype = {
|
55
|
+
isEven: function() {
|
56
|
+
return this.value % 2 === 0;
|
57
|
+
},
|
58
|
+
isOdd: function() {
|
59
|
+
return this.value % 2 === 1;
|
60
|
+
}
|
61
|
+
};
|
62
|
+
|
63
|
+
Datey = function() {};
|
64
|
+
|
65
|
+
rules = {
|
66
|
+
plural: [],
|
67
|
+
singular: [],
|
68
|
+
irregular: [],
|
69
|
+
uncountable: []
|
70
|
+
};
|
71
|
+
|
72
|
+
inflect = {
|
73
|
+
plural: function(matcher, suffix) {
|
74
|
+
return rules.plural.push([matcher, suffix]);
|
75
|
+
},
|
76
|
+
singular: function(matcher, suffix) {
|
77
|
+
return rules.singular.push([matcher, suffix]);
|
78
|
+
},
|
79
|
+
irregular: function(matcher, suffix) {
|
80
|
+
return rules.irregular.push([matcher, suffix]);
|
81
|
+
},
|
82
|
+
uncountable: function(words) {
|
83
|
+
return rules.uncountable = words;
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
inflect.plural(/$/, 's');
|
88
|
+
|
89
|
+
inflect.plural(/s$/i, 's');
|
90
|
+
|
91
|
+
inflect.plural(/^(ax|test)is$/i, '$1es');
|
92
|
+
|
93
|
+
inflect.plural(/(octop|vir)us$/i, '$1i');
|
94
|
+
|
95
|
+
inflect.plural(/(octop|vir)i$/i, '$1i');
|
96
|
+
|
97
|
+
inflect.plural(/(alias|status)$/i, '$1es');
|
98
|
+
|
99
|
+
inflect.plural(/(bu)s$/i, '$1ses');
|
100
|
+
|
101
|
+
inflect.plural(/(buffal|tomat)o$/i, '$1oes');
|
102
|
+
|
103
|
+
inflect.plural(/([ti])um$/i, '$1a');
|
104
|
+
|
105
|
+
inflect.plural(/([ti])a$/i, '$1a');
|
106
|
+
|
107
|
+
inflect.plural(/sis$/i, 'ses');
|
108
|
+
|
109
|
+
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '$1$2ves');
|
110
|
+
|
111
|
+
inflect.plural(/(hive)$/i, '$1s');
|
112
|
+
|
113
|
+
inflect.plural(/([^aeiouy]|qu)y$/i, '$1ies');
|
114
|
+
|
115
|
+
inflect.plural(/(x|ch|ss|sh)$/i, '$1es');
|
116
|
+
|
117
|
+
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '$1ices');
|
118
|
+
|
119
|
+
inflect.plural(/(m|l)ouse$/i, '$1ice');
|
120
|
+
|
121
|
+
inflect.plural(/(m|l)ice$/i, '$1ice');
|
122
|
+
|
123
|
+
inflect.plural(/^(ox)$/i, '$1en');
|
124
|
+
|
125
|
+
inflect.plural(/^(oxen)$/i, '$1');
|
126
|
+
|
127
|
+
inflect.plural(/(quiz)$/i, '$1zes');
|
128
|
+
|
129
|
+
inflect.singular(/s$/i, '');
|
130
|
+
|
131
|
+
inflect.singular(/(ss)$/i, '$1');
|
132
|
+
|
133
|
+
inflect.singular(/(n)ews$/i, '$1ews');
|
134
|
+
|
135
|
+
inflect.singular(/([ti])a$/i, '$1um');
|
136
|
+
|
137
|
+
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1$2sis');
|
138
|
+
|
139
|
+
inflect.singular(/(^analy)(sis|ses)$/i, '$1sis');
|
140
|
+
|
141
|
+
inflect.singular(/([^f])ves$/i, '$1fe');
|
142
|
+
|
143
|
+
inflect.singular(/(hive)s$/i, '$1');
|
144
|
+
|
145
|
+
inflect.singular(/(tive)s$/i, '$1');
|
146
|
+
|
147
|
+
inflect.singular(/([lr])ves$/i, '$1f');
|
148
|
+
|
149
|
+
inflect.singular(/([^aeiouy]|qu)ies$/i, '$1y');
|
150
|
+
|
151
|
+
inflect.singular(/(s)eries$/i, '$1eries');
|
152
|
+
|
153
|
+
inflect.singular(/(m)ovies$/i, '$1ovie');
|
154
|
+
|
155
|
+
inflect.singular(/(x|ch|ss|sh)es$/i, '$1');
|
156
|
+
|
157
|
+
inflect.singular(/(m|l)ice$/i, '$1ouse');
|
158
|
+
|
159
|
+
inflect.singular(/(bus)(es)?$/i, '$1');
|
160
|
+
|
161
|
+
inflect.singular(/(o)es$/i, '$1');
|
162
|
+
|
163
|
+
inflect.singular(/(shoe)s$/i, '$1');
|
164
|
+
|
165
|
+
inflect.singular(/(cris|test)(is|es)$/i, '$1is');
|
166
|
+
|
167
|
+
inflect.singular(/^(a)x[ie]s$/i, '$1xis');
|
168
|
+
|
169
|
+
inflect.singular(/(octop|vir)(us|i)$/i, '$1us');
|
170
|
+
|
171
|
+
inflect.singular(/(alias|status)(es)?$/i, '$1');
|
172
|
+
|
173
|
+
inflect.singular(/^(ox)en/i, '$1');
|
174
|
+
|
175
|
+
inflect.singular(/(vert|ind)ices$/i, '$1ex');
|
176
|
+
|
177
|
+
inflect.singular(/(matr)ices$/i, '$1ix');
|
178
|
+
|
179
|
+
inflect.singular(/(quiz)zes$/i, '$1');
|
180
|
+
|
181
|
+
inflect.singular(/(database)s$/i, '$1');
|
182
|
+
|
183
|
+
inflect.irregular('person', 'people');
|
184
|
+
|
185
|
+
inflect.irregular('man', 'men');
|
186
|
+
|
187
|
+
inflect.irregular('woman', 'women');
|
188
|
+
|
189
|
+
inflect.irregular('child', 'children');
|
190
|
+
|
191
|
+
inflect.irregular('sex', 'sexes');
|
192
|
+
|
193
|
+
inflect.irregular('move', 'moves');
|
194
|
+
|
195
|
+
inflect.irregular('cow', 'kine');
|
196
|
+
|
197
|
+
inflect.irregular('zombie', 'zombies');
|
198
|
+
|
199
|
+
inflect.uncountable(['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'bacon']);
|
200
|
+
|
201
|
+
Stringy = function(obj) {
|
202
|
+
return this.value = obj;
|
203
|
+
};
|
204
|
+
|
205
|
+
Stringy.prototype = {
|
206
|
+
capitalize: function() {
|
207
|
+
var lowerCased, word;
|
208
|
+
if (this.value === '') return this.value;
|
209
|
+
lowerCased = this.value.toLowerCase();
|
210
|
+
word = lowerCased[0].toUpperCase() + lowerCased.substring(1);
|
211
|
+
return word;
|
212
|
+
},
|
213
|
+
numbers: function() {
|
214
|
+
return parseFloat(this.value.replace(/[^0-9.-]+/g, ""));
|
215
|
+
},
|
216
|
+
underscore: function() {
|
217
|
+
var ch, underscored;
|
218
|
+
underscored = [];
|
219
|
+
for (ch in this.value.split("")) {
|
220
|
+
if (ch !== 0 && this.value[ch].match(/[A-Z|\s]/)) underscored.push("_");
|
221
|
+
if (!this.value[ch].match(/\s/)) {
|
222
|
+
underscored.push(this.value[ch].toLowerCase());
|
223
|
+
}
|
224
|
+
}
|
225
|
+
underscored = underscored.join("");
|
226
|
+
return underscored.replace(/^_?/, "");
|
227
|
+
},
|
228
|
+
camel: function() {
|
229
|
+
return f(f(this.value).underscore()).titleize().replace(RegExp(" ", "g"), "");
|
230
|
+
},
|
231
|
+
humanize: function() {
|
232
|
+
var ch, humanized;
|
233
|
+
humanized = [];
|
234
|
+
for (ch in this.value.split("")) {
|
235
|
+
if (ch !== 0 && this.value[ch].match(/[A-Z]/)) humanized.push("_");
|
236
|
+
if (!this.value[ch].match(/\-/)) humanized.push(this.value[ch]);
|
237
|
+
}
|
238
|
+
humanized = humanized.join("").split("_");
|
239
|
+
humanized[0] = f(humanized[0]).capitalize();
|
240
|
+
return humanized.join(" ").trim();
|
241
|
+
},
|
242
|
+
pluralize: function() {
|
243
|
+
var i, r;
|
244
|
+
if (rules.uncountable.indexOf(this.value) > 0) return this.value;
|
245
|
+
i = rules.irregular.length;
|
246
|
+
while (i > 0) {
|
247
|
+
r = rules.irregular[i - 1];
|
248
|
+
if (this.value === r[0]) return r[1];
|
249
|
+
i--;
|
250
|
+
}
|
251
|
+
i = rules.plural.length;
|
252
|
+
while (i > 0) {
|
253
|
+
r = rules.plural[i - 1];
|
254
|
+
if (this.value.match(r[0])) return this.value.replace(r[0], r[1]);
|
255
|
+
i--;
|
256
|
+
}
|
257
|
+
},
|
258
|
+
singularize: function() {
|
259
|
+
var i, r;
|
260
|
+
if (rules.uncountable.indexOf(this.value) > 0) return this.value;
|
261
|
+
i = rules.irregular.length;
|
262
|
+
while (i > 0) {
|
263
|
+
r = rules.irregular[i - 1];
|
264
|
+
if (this.value === r[1]) return r[0];
|
265
|
+
i--;
|
266
|
+
}
|
267
|
+
i = rules.singular.length;
|
268
|
+
while (i > 0) {
|
269
|
+
r = rules.singular[i - 1];
|
270
|
+
if (this.value.match(r[0])) return this.value.replace(r[0], r[1]);
|
271
|
+
i--;
|
272
|
+
}
|
273
|
+
},
|
274
|
+
money: function(options) {
|
275
|
+
var defaults, first, i, j, last, middle, prop, sign, val;
|
276
|
+
options || (options = {});
|
277
|
+
defaults = {
|
278
|
+
precision: 2,
|
279
|
+
symbol: "$",
|
280
|
+
dot: ".",
|
281
|
+
seperator: ",",
|
282
|
+
"default": "-"
|
283
|
+
};
|
284
|
+
for (prop in defaults) {
|
285
|
+
(options[prop] !== void 0) || (options[prop] = defaults[prop]);
|
286
|
+
}
|
287
|
+
if (!this.value) {
|
288
|
+
return options.defaults;
|
289
|
+
} else {
|
290
|
+
val = parseFloat(this.value);
|
291
|
+
sign = (val < 0 ? "-" : "");
|
292
|
+
i = parseInt(val = Math.abs(+val || 0).toFixed(options.precision)) + "";
|
293
|
+
j = ((j = i.length) > 3 ? j % 3 : 0);
|
294
|
+
first = sign + options.symbol + (j ? i.substr(0, j) + options.seperator : "");
|
295
|
+
middle = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + options.seperator);
|
296
|
+
last = (options.precision ? options.dot + Math.abs(val - i).toFixed(options.precision).slice(2) : "");
|
297
|
+
return first + middle + last;
|
298
|
+
}
|
299
|
+
},
|
300
|
+
number: function(opts) {
|
301
|
+
opts = opts || {};
|
302
|
+
opts.symbol = "";
|
303
|
+
return f(this.value).money(opts);
|
304
|
+
},
|
305
|
+
titleize: function() {
|
306
|
+
var parts, word;
|
307
|
+
parts = this.value.split(RegExp('[ _]'));
|
308
|
+
parts = (function() {
|
309
|
+
var _i, _len, _results;
|
310
|
+
_results = [];
|
311
|
+
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
312
|
+
word = parts[_i];
|
313
|
+
_results.push(f(word).capitalize());
|
314
|
+
}
|
315
|
+
return _results;
|
316
|
+
})();
|
317
|
+
return parts.join(" ");
|
318
|
+
},
|
319
|
+
isBlank: function() {
|
320
|
+
var clean;
|
321
|
+
clean = this.value || "";
|
322
|
+
clean = clean.replace(RegExp(' ', 'g'), "");
|
323
|
+
return clean === "";
|
324
|
+
},
|
325
|
+
truncate: function(amount, tail) {
|
326
|
+
var parts, str;
|
327
|
+
if (tail == null) tail = "...";
|
328
|
+
parts = [];
|
329
|
+
parts = (function() {
|
330
|
+
var _i, _len, _ref, _results;
|
331
|
+
_ref = this.value;
|
332
|
+
_results = [];
|
333
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
334
|
+
str = _ref[_i];
|
335
|
+
if (_i < amount) _results.push(str);
|
336
|
+
}
|
337
|
+
return _results;
|
338
|
+
}).call(this);
|
339
|
+
return parts.join("") + tail;
|
340
|
+
}
|
341
|
+
};
|
342
|
+
|
343
|
+
window.ALT159 = window.f = (function(obj) {
|
344
|
+
var ALT159;
|
345
|
+
ALT159 = function(obj) {
|
346
|
+
if (typeof obj === "string") return new Stringy(obj);
|
347
|
+
if (toString.call(obj) === "[object Number]") return new Numbery(obj);
|
348
|
+
if (toString.call(obj) === "[object Date]") return new Datey(obj);
|
349
|
+
if (obj === void 0) return new Lagniappe();
|
350
|
+
return null;
|
351
|
+
};
|
352
|
+
ALT159.types = {
|
353
|
+
Stringy: Stringy,
|
354
|
+
Numbery: Numbery,
|
355
|
+
Datey: Datey
|
356
|
+
};
|
357
|
+
return ALT159;
|
358
|
+
})();
|
359
|
+
|
360
|
+
}).call(this);
|