开发者

Javascript - Function returning different result when imported from a package

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜