mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Core: Deprecate jQuery.trim
Fixes gh-4363
Closes gh-4461
(cherry picked from 5ea5946094
)
This commit is contained in:
parent
2f666c1dab
commit
56e73e0c4a
13
src/core.js
13
src/core.js
@ -34,11 +34,7 @@ var
|
|||||||
// The jQuery object is actually just the init constructor 'enhanced'
|
// The jQuery object is actually just the init constructor 'enhanced'
|
||||||
// Need init if jQuery is called (just allow error to be thrown if not included)
|
// Need init if jQuery is called (just allow error to be thrown if not included)
|
||||||
return new jQuery.fn.init( selector, context );
|
return new jQuery.fn.init( selector, context );
|
||||||
},
|
};
|
||||||
|
|
||||||
// Support: Android <=4.0 only
|
|
||||||
// Make sure we trim BOM and NBSP
|
|
||||||
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
|
|
||||||
|
|
||||||
jQuery.fn = jQuery.prototype = {
|
jQuery.fn = jQuery.prototype = {
|
||||||
|
|
||||||
@ -275,13 +271,6 @@ jQuery.extend( {
|
|||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Support: Android <=4.0 only
|
|
||||||
trim: function( text ) {
|
|
||||||
return text == null ?
|
|
||||||
"" :
|
|
||||||
( text + "" ).replace( rtrim, "" );
|
|
||||||
},
|
|
||||||
|
|
||||||
// results is for internal usage only
|
// results is for internal usage only
|
||||||
makeArray: function( arr, results ) {
|
makeArray: function( arr, results ) {
|
||||||
var ret = results || [];
|
var ret = results || [];
|
||||||
|
@ -12,6 +12,10 @@ define( [
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// Support: Android <=4.0 only
|
||||||
|
// Make sure we trim BOM and NBSP
|
||||||
|
var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
|
||||||
|
|
||||||
jQuery.fn.extend( {
|
jQuery.fn.extend( {
|
||||||
|
|
||||||
bind: function( types, data, fn ) {
|
bind: function( types, data, fn ) {
|
||||||
@ -95,4 +99,9 @@ jQuery.isNumeric = function( obj ) {
|
|||||||
!isNaN( obj - parseFloat( obj ) );
|
!isNaN( obj - parseFloat( obj ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jQuery.trim = function( text ) {
|
||||||
|
return text == null ?
|
||||||
|
"" :
|
||||||
|
( text + "" ).replace( rtrim, "" );
|
||||||
|
};
|
||||||
} );
|
} );
|
||||||
|
@ -76,12 +76,11 @@ QUnit.test( "show/hide", function( assert ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QUnit.test( "core", function( assert ) {
|
QUnit.test( "core", function( assert ) {
|
||||||
assert.expect( 18 );
|
assert.expect( 17 );
|
||||||
|
|
||||||
var elem = jQuery( "<div></div><span></span>" );
|
var elem = jQuery( "<div></div><span></span>" );
|
||||||
|
|
||||||
assert.strictEqual( elem.length, 2, "Correct number of elements" );
|
assert.strictEqual( elem.length, 2, "Correct number of elements" );
|
||||||
assert.strictEqual( jQuery.trim( " hello " ), "hello", "jQuery.trim" );
|
|
||||||
|
|
||||||
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
|
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
|
||||||
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
|
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );
|
||||||
|
@ -216,28 +216,6 @@ QUnit.test( "noConflict", function( assert ) {
|
|||||||
window[ "jQuery" ] = jQuery = $$;
|
window[ "jQuery" ] = jQuery = $$;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "trim", function( assert ) {
|
|
||||||
assert.expect( 13 );
|
|
||||||
|
|
||||||
var nbsp = String.fromCharCode( 160 );
|
|
||||||
|
|
||||||
assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
|
|
||||||
assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
|
|
||||||
assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
|
|
||||||
assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " );
|
|
||||||
|
|
||||||
assert.equal( jQuery.trim(), "", "Nothing in." );
|
|
||||||
assert.equal( jQuery.trim( undefined ), "", "Undefined" );
|
|
||||||
assert.equal( jQuery.trim( null ), "", "Null" );
|
|
||||||
assert.equal( jQuery.trim( 5 ), "5", "Number" );
|
|
||||||
assert.equal( jQuery.trim( false ), "false", "Boolean" );
|
|
||||||
|
|
||||||
assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
|
|
||||||
assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
|
|
||||||
assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
|
|
||||||
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "isPlainObject", function( assert ) {
|
QUnit.test( "isPlainObject", function( assert ) {
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
|
|
||||||
|
@ -600,3 +600,25 @@ QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "isNumeric(Symbol)", fu
|
|||||||
assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" );
|
assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" );
|
||||||
assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" );
|
assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
QUnit.test( "trim", function( assert ) {
|
||||||
|
assert.expect( 13 );
|
||||||
|
|
||||||
|
var nbsp = String.fromCharCode( 160 );
|
||||||
|
|
||||||
|
assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
|
||||||
|
assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
|
||||||
|
assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
|
||||||
|
assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " );
|
||||||
|
|
||||||
|
assert.equal( jQuery.trim(), "", "Nothing in." );
|
||||||
|
assert.equal( jQuery.trim( undefined ), "", "Undefined" );
|
||||||
|
assert.equal( jQuery.trim( null ), "", "Null" );
|
||||||
|
assert.equal( jQuery.trim( 5 ), "5", "Number" );
|
||||||
|
assert.equal( jQuery.trim( false ), "false", "Boolean" );
|
||||||
|
|
||||||
|
assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
|
||||||
|
assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
|
||||||
|
assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
|
||||||
|
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
|
||||||
|
} );
|
||||||
|
Loading…
Reference in New Issue
Block a user