@@ -176,6 +176,12 @@ function isElement ( value: unknown ): value is HTMLElement {
176176
177177}
178178
179+ function isText ( value : unknown ) : value is Text {
180+
181+ return ! ! value && value . nodeType === 3 ;
182+
183+ }
184+
179185function isBoolean ( value : unknown ) : value is boolean {
180186
181187 return typeof value === 'boolean' ;
@@ -319,34 +325,6 @@ fn.empty = function ( this: Cash ) {
319325} ;
320326
321327
322- // @require core/cash.ts
323- // @require core/type_checking.ts
324- // @require collection/each.ts
325-
326- interface Cash {
327- text ( ) : string ;
328- text ( text : string ) : this;
329- }
330-
331- function text ( this : Cash ) : string ;
332- function text ( this : Cash , text : string ) : Cash ;
333- function text ( this : Cash , text ?: string ) {
334-
335- if ( isUndefined ( text ) ) return this [ 0 ] ? this [ 0 ] . textContent : '' ;
336-
337- return this . each ( ( i , ele ) => {
338-
339- if ( ! isElement ( ele ) ) return ;
340-
341- ele . textContent = text
342-
343- } ) ;
344-
345- } ;
346-
347- fn . text = text ;
348-
349-
350328// @require ./cash.ts
351329// @require ./type_checking.ts
352330
@@ -650,6 +628,39 @@ fn.last = function ( this: Cash ) {
650628} ;
651629
652630
631+ // @require core/cash.ts
632+ // @require core/type_checking.ts
633+ // @require collection/each.ts
634+ // @require collection/get.ts
635+
636+ interface Cash {
637+ text ( ) : string ;
638+ text ( text : string ) : this;
639+ }
640+
641+ function text ( this : Cash ) : string ;
642+ function text ( this : Cash , text : string ) : Cash ;
643+ function text ( this : Cash , text ?: string ) {
644+
645+ if ( isUndefined ( text ) ) {
646+
647+ return this . get ( ) . map ( ele => isElement ( ele ) || isText ( ele ) ? ele . textContent : '' ) . join ( '' ) ;
648+
649+ }
650+
651+ return this . each ( ( i , ele ) => {
652+
653+ if ( ! isElement ( ele ) ) return ;
654+
655+ ele . textContent = text ;
656+
657+ } ) ;
658+
659+ }
660+
661+ fn . text = text ;
662+
663+
653664// @require core/type_checking.ts
654665// @require core/variables.ts
655666
0 commit comments