import type { Node } from 'domhandler' ; import type { Cheerio } from '../cheerio' ; import { isTag } from '../utils' ; const submittableSelector = 'input,select,textarea,keygen' ; const r20 = /%20/g ; const rCRLF = /\r?\n/g ; category returns see https export function serialize < T extends Node > ( this ) { const arr = this . serializeArray ( ) ; const retArr = arr . map ( ( data ) => `${ encodeURIComponent ( data . name ) }=${ encodeURIComponent ( data . value ) }` ) ; return retArr . join ( '&' ) . replace ( r20 , '+' ) ; } interface SerializedField { name : string ; value : string ; } category example returns see https export function serializeArray < T extends Node > ( this ) { return this . map ( ( _ , elem ) => { const $elem = this . _make ( elem ) ; if ( isTag ( elem ) && elem . name === 'form' ) { return $elem . find ( submittableSelector ) . toArray ( ) ; } return $elem . filter ( submittableSelector ) . toArray ( ) ; } ) . filter ( '[name!=""]:enabled' + ':not(:submit, :button, :image, :reset, :file)' + ':matches([checked], :not(:checkbox, :radio))' ) . map < Node , SerializedField > ( ( _ , elem ) => { const $elem = this . _make ( elem ) ; const name = $elem . attr ( 'name' ) as string ; const value = $elem . val ( ) ?? '' ; if ( Array . isArray ( value ) ) { return value . map ( ( val ) => ( { name , value : val . replace ( rCRLF , '\r\n' ) } ) ) ; } return { name , value : value . replace ( rCRLF , '\r\n' ) } ; } ) . toArray ( ) ; }