I have a function that is a part of my utils
package that I import in my other modules:
export function urlQueryParamParser(params: URLSearchParams) {
const output:any = {};
const searchParams = new URLSearchParams(params);
new Set([...searchParams.keys()])
.forEach(key => {
output[key] = searchParams.getAll(key).length > 1 ?
searchParams.getAll(key) :
searchParams.get(key)
});
return output;
}
I export it like this:
export * from './utils/urlQueryParamParser'
When I import it to my m开发者_如何学编程odule:
import { urlQueryParamParser } from '@mypackages/utils'
and use it urlQueryParamParser(params)
I get:
{
"[object Iterator]": null
}
Where, if I just copy the function and use it as a part of the file where I am actually calling it, I get the right return result, something like this:
{
"filter": "all",
"query": "",
"range": "today",
"from": "2022-11-22",
"to": "2022-12-22",
"claims": [
"damaged",
"missing-article"
]
}
Why is the result different when I import this function as part of the other package and when I use it as a function from the file where I am using it?
精彩评论