]> source.dussan.org Git - jquery.git/commitdiff
Core: Compress stripAndCollapse
authorRichard Gibson <richard.gibson@gmail.com>
Fri, 16 Sep 2016 02:42:34 +0000 (22:42 -0400)
committerTimmy Willison <4timmywil@gmail.com>
Mon, 19 Sep 2016 13:19:48 +0000 (09:19 -0400)
Close gh-3318

src/core/stripAndCollapse.js

index 797d9f53196c733bd243051089626d2f0207fcad..ccad6602ecb5167eb6f459427051f5ce0edf1c79 100644 (file)
@@ -1,12 +1,14 @@
-define( function() {
+define( [
+       "../var/rnothtmlwhite"
+], function( rnothtmlwhite ) {
        "use strict";
 
        // Strip and collapse whitespace according to HTML spec
        // https://html.spec.whatwg.org/multipage/infrastructure.html#strip-and-collapse-whitespace
-       var rhtmlSpace = /[\x20\t\r\n\f]+/g,
-               stripAndCollapse = function( value ) {
-                       return ( " " + value + " " ).replace( rhtmlSpace, " " ).slice( 1, -1 );
-               };
+       function stripAndCollapse( value ) {
+               var tokens = value.match( rnothtmlwhite ) || [];
+               return tokens.join( " " );
+       }
 
        return stripAndCollapse;
 } );