Skip to content

Commit 5294228

Browse files
Merge pull request #2760 from SergioCrisostomo/rename-from-to-convert
Rename <Type>.from to <Type>.convert
2 parents 8ce77d1 + 509c953 commit 5294228

File tree

11 files changed

+51
-46
lines changed

11 files changed

+51
-46
lines changed

Docs/Core/Core.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ If you really need this function you can implement it like so:
285285
Function: $empty {#Deprecated-Functions:empty}
286286
-------------------------
287287

288-
This method has been deprecated. Use [Function.from](/core/Types/Function#Function:Function-from) instead.
288+
This method has been deprecated. Use [Function.convert](/core/Types/Function#Function:Function:convert) instead.
289289

290290
### Example:
291291

292-
var myFunc = Function.from();
292+
var myFunc = Function.convert();
293293
// or better:
294294
var myFunc = function(){};
295295

@@ -298,11 +298,11 @@ This method has been deprecated. Use [Function.from](/core/Types/Function#Functi
298298
Function: $lambda {#Deprecated-Functions:lambda}
299299
---------------------------
300300

301-
This method has been deprecated. Use [Function.from](/core/Types/Function#Function:Function-from) instead.
301+
This method has been deprecated. Use [Function.convert](/core/Types/Function#Function:Function:convert) instead.
302302

303303
### Example:
304304

305-
myLink.addEvent('click', Function.from(false)); // prevents a link Element from being clickable
305+
myLink.addEvent('click', Function.convert(false)); // prevents a link Element from being clickable
306306

307307

308308

Docs/Types/Function.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Function Methods.
99

1010

1111

12-
Function: Function.from {#Function:Function-from}
12+
Function: Function.convert {#Function:Function:convert}
1313
-------------------------------------------------
1414

1515
If the passed argument is a function, it will return itself. Otherwise, it will return a function that returns the passed argument.
1616

1717
### Syntax:
1818

19-
var foo = Function.from(obj);
19+
var foo = Function.convert(obj);
2020

2121
### Arguments:
2222

@@ -28,18 +28,18 @@ If the passed argument is a function, it will return itself. Otherwise, it will
2828

2929
### Examples:
3030

31-
var fn = Function.from(42);
31+
var fn = Function.convert(42);
3232
alert(fn()); // alerts '42'
3333

34-
var fn2 = Function.from(fn);
34+
var fn2 = Function.convert(fn);
3535
alert(fn2()); // alerts '42'
3636

3737
### Notes:
3838

3939
This function is equivalent to the following deprecated MooTools 1.2 methods:
4040

41-
var fn1 = Function.from(); // equivalent to var fn1 = function(){};
42-
var fn2 = Function.from(foo); // equivalent to var fn2 = function(){ return foo; };
41+
var fn1 = Function.convert(); // equivalent to var fn1 = function(){};
42+
var fn2 = Function.convert(foo); // equivalent to var fn2 = function(){ return foo; };
4343

4444

4545
Function: Function.attempt {#Function:Function-attempt}

Docs/Types/Number.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Every Math method is mirrored in the Number object, both as prototype and generi
1313

1414

1515

16-
Function: Number.from {#Number:Number-from}
16+
Function: Number.convert {#Number:Number:convert}
1717
------------------------------------
1818

1919
Returns the passed parameter as a Number, or null if not a number.
2020

2121
### Syntax:
2222

23-
Number.from(arg);
23+
Number.convert(arg);
2424

2525
### Arguments:
2626

@@ -33,8 +33,8 @@ Returns the passed parameter as a Number, or null if not a number.
3333

3434
### Example:
3535

36-
Number.from('12') // returns 12
37-
Number.from('hello') // returns null
36+
Number.convert('12') // returns 12
37+
Number.convert('hello') // returns null
3838

3939

4040

Docs/Types/String.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ A collection of the String Object methods and functions.
99

1010

1111

12-
Function: String.from {#String:String-from}
12+
Function: String.convert {#String:String:convert}
1313
------------------------------------
1414

1515
Returns the passed parameter as a String.
1616

1717
### Syntax:
1818

19-
String.from(arg);
19+
String.convert(arg);
2020

2121
### Arguments:
2222

@@ -28,8 +28,8 @@ Returns the passed parameter as a String.
2828

2929
### Example:
3030

31-
String.from(2); // returns '2'
32-
String.from(true); // returns 'true'
31+
String.convert(2); // returns '2'
32+
String.convert(true); // returns 'true'
3333

3434

3535

Source/Browser/Browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ Browser.extend({
170170

171171
this.Window = this.$constructor = new Type('Window', function(){});
172172

173-
this.$family = Function.from('window').hide();
173+
this.$family = Function.convert('window').hide();
174174

175175
Window.mirror(function(name, method){
176176
window[name] = method;
177177
});
178178

179179
this.Document = document.$constructor = new Type('Document', function(){});
180180

181-
document.$family = Function.from('document').hide();
181+
document.$family = Function.convert('document').hide();
182182

183183
Document.mirror(function(name, method){
184184
document[name] = method;

Source/Core/Core.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,30 @@ Array.convert = function(item){
127127
return (Type.isEnumerable(item) && typeof item != 'string') ? (typeOf(item) == 'array') ? item : slice.call(item) : [item];
128128
};
129129

130-
Function.from = function(item){
130+
Function.convert = function(item){
131131
return (typeOf(item) == 'function') ? item : function(){
132132
return item;
133133
};
134134
};
135135

136-
/*<1.5compat>*/
137-
Array.from = Array.convert;
138-
/*</1.5compat>*/
139136

140-
Number.from = function(item){
137+
Number.convert = function(item){
141138
var number = parseFloat(item);
142139
return isFinite(number) ? number : null;
143140
};
144141

145-
String.from = function(item){
142+
String.convert = function(item){
146143
return item + '';
147144
};
148145

146+
/*<1.5compat>*/
147+
Array.from = Array.convert;
148+
/*</1.5compat>*/
149+
150+
Function.from = Function.convert;
151+
Number.from = Number.convert;
152+
String.from = String.convert;
153+
149154
// hide, protect
150155

151156
Function.implement({
@@ -527,7 +532,7 @@ this.$merge = function(){
527532
return Object.merge.apply(null, args);
528533
};
529534

530-
this.$lambda = Function.from;
535+
this.$lambda = Function.convert;
531536
this.$mixin = Object.merge;
532537
this.$random = Number.random;
533538
this.$splat = Array.convert;

Source/Element/Element.Event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Element.Properties.events = {set: function(events){
3939
return true;
4040
};
4141
}
42-
if (custom.base) realType = Function.from(custom.base).call(this, type);
42+
if (custom.base) realType = Function.convert(custom.base).call(this, type);
4343
}
4444
var defn = function(){
4545
return fn.call(self);
@@ -70,7 +70,7 @@ Element.Properties.events = {set: function(events){
7070
var custom = Element.Events[type];
7171
if (custom){
7272
if (custom.onRemove) custom.onRemove.call(this, fn, type);
73-
if (custom.base) type = Function.from(custom.base).call(this, type);
73+
if (custom.base) type = Function.convert(custom.base).call(this, type);
7474
}
7575
return (Element.NativeEvents[type]) ? this.removeListener(type, value, arguments[2]) : this;
7676
},

Source/Element/Element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ if (!Browser.Element){
7373

7474
Element.Prototype = {
7575
'$constructor': Element,
76-
'$family': Function.from('element').hide()
76+
'$family': Function.convert('element').hide()
7777
};
7878

7979
Element.mirror(function(name, method){

Source/Fx/Fx.CSS.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Fx.CSS = new Class({
5252
//parses a value into an array
5353

5454
parse: function(value){
55-
value = Function.from(value)();
55+
value = Function.convert(value)();
5656
value = (typeof value == 'string') ? value.split(' ') : Array.convert(value);
5757
return value.map(function(val){
5858
val = String(val);
@@ -74,7 +74,7 @@ Fx.CSS = new Class({
7474
(Math.min(from.length, to.length)).times(function(i){
7575
computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser});
7676
});
77-
computed.$family = Function.from('fx:css:value');
77+
computed.$family = Function.convert('fx:css:value');
7878
return computed;
7979
},
8080

@@ -159,7 +159,7 @@ Fx.CSS.Parsers = {
159159
},
160160

161161
String: {
162-
parse: Function.from(false),
162+
parse: Function.convert(false),
163163
compute: function(zero, one){
164164
return one;
165165
},

Specs/Core/Core.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,39 +666,39 @@ describe('Array.convert', function(){
666666
});
667667
});
668668

669-
describe('String.from', function(){
669+
describe('String.convert', function(){
670670

671671
it('should convert to type string', function(){
672-
expect(typeOf(String.from('string'))).to.equal('string');
673-
expect(typeOf(String.from(1))).to.equal('string');
674-
expect(typeOf(String.from(new Date))).to.equal('string');
675-
expect(typeOf(String.from(function(){}))).to.equal('string');
672+
expect(typeOf(String.convert('string'))).to.equal('string');
673+
expect(typeOf(String.convert(1))).to.equal('string');
674+
expect(typeOf(String.convert(new Date))).to.equal('string');
675+
expect(typeOf(String.convert(function(){}))).to.equal('string');
676676
});
677677

678678
});
679679

680-
describe('Function.from', function(){
680+
describe('Function.convert', function(){
681681

682682
it('if a function is passed in that function should be returned', function(){
683683
var fn = function(a){ return a; };
684-
expect(Function.from(fn)).to.equal(fn);
684+
expect(Function.convert(fn)).to.equal(fn);
685685
});
686686

687687
it('should return a function that returns the value passed when called', function(){
688-
expect(Function.from('hello world!')()).to.equal('hello world!');
688+
expect(Function.convert('hello world!')()).to.equal('hello world!');
689689
});
690690

691691
});
692692

693-
describe('Number.from', function(){
693+
describe('Number.convert', function(){
694694

695695
it('should return the number representation of a string', function(){
696-
expect(Number.from('10')).to.equal(10);
697-
expect(Number.from('10px')).to.equal(10);
696+
expect(Number.convert('10')).to.equal(10);
697+
expect(Number.convert('10px')).to.equal(10);
698698
});
699699

700700
it('should return null when it fails to return a number type', function(){
701-
expect(Number.from('ciao')).to.equal(null);
701+
expect(Number.convert('ciao')).to.equal(null);
702702
});
703703

704704
});

0 commit comments

Comments
 (0)