File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1- import { parse , format } from 'url' ;
1+ import { format } from 'url' ;
22import { unescape } from 'querystring' ;
33
4+ const PROTOCOL_RE = / ^ [ a - z 0 - 9 . + - ] + : / i;
5+
6+ const hasProtocolLikeNode = ( str : unknown ) : boolean => {
7+ if ( typeof str !== 'string' ) throw new TypeError ( 'url must be a string' ) ;
8+ return PROTOCOL_RE . test ( str . trim ( ) ) ;
9+ } ;
10+
411const decodeURL = ( str : string ) => {
5- if ( parse ( str ) . protocol ) {
12+ if ( hasProtocolLikeNode ( str ) ) {
613 const parsed = new URL ( str ) ;
714
815 // Exit if input is a data url
Original file line number Diff line number Diff line change 1- import { parse , format } from 'url' ;
1+ import { format } from 'url' ;
22import { unescape } from 'querystring' ;
33
4+ const PROTOCOL_RE = / ^ [ a - z 0 - 9 . + - ] + : / i;
5+
6+ const hasProtocolLikeNode = ( str : unknown ) : boolean => {
7+ if ( typeof str !== 'string' ) throw new TypeError ( 'url must be a string' ) ;
8+ return PROTOCOL_RE . test ( str . trim ( ) ) ;
9+ } ;
10+
411const encodeURL = ( str : string ) => {
5- if ( parse ( str ) . protocol ) {
12+ if ( hasProtocolLikeNode ( str ) ) {
613 const parsed = new URL ( str ) ;
714
815 // Exit if input is a data url
You can’t perform that action at this time.
0 commit comments