MCPcopy Create free account
hub / github.com/angular/angular / search

Method search

packages/common/upgrade/src/location_shim.ts:659–699  ·  view source on GitHub ↗
(
    search?: string | number | {[key: string]: unknown},
    paramValue?: null | undefined | string | number | boolean | string[],
  )

Source from the content-addressed store, hash-verified

657 paramValue: null | undefined | string | number | boolean | string[],
658 ): this;
659 search(
660 search?: string | number | {[key: string]: unknown},
661 paramValue?: null | undefined | string | number | boolean | string[],
662 ): {[key: string]: unknown} | this {
663 switch (arguments.length) {
664 case 0:
665 return this.$$search;
666 case 1:
667 if (typeof search === 'string' || typeof search === 'number') {
668 this.$$search = this.urlCodec.decodeSearch(search.toString());
669 } else if (typeof search === 'object' && search !== null) {
670 // Copy the object into a null-prototype object so it's never mutated and immune to prototype pollution
671 const searchObj: {[key: string]: unknown} = Object.create(null);
672 for (const [key, value] of Object.entries(search)) {
673 if (value != null) {
674 searchObj[key] = value;
675 }
676 }
677
678 this.$$search = searchObj;
679 } else {
680 throw new Error(
681 'LocationProvider.search(): First argument must be a string or an object.',
682 );
683 }
684 break;
685 default:
686 if (typeof search === 'string') {
687 const currentSearch = this.search();
688 if (typeof paramValue === 'undefined' || paramValue === null) {
689 delete currentSearch[search];
690 return this.search(currentSearch);
691 } else {
692 currentSearch[search] = paramValue;
693 return this.search(currentSearch);
694 }
695 }
696 }
697 this.composeUrls();
698 return this;
699 }
700
701 /**
702 * Retrieves the current hash fragment, or changes the hash fragment and returns a reference to

Callers 7

urlMethod · 0.95
formatTemplateFunction · 0.45
getConditionMethod · 0.45
upgrade.spec.tsFile · 0.45
constructorMethod · 0.45
searchWithQueryMethod · 0.45

Calls 5

composeUrlsMethod · 0.95
decodeSearchMethod · 0.80
toStringMethod · 0.65
createMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected