All files / getUrlSearch getUrlSearch.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                      1x 1x 1x    
/**
 * @description 传入对象,转换为url参数,结果符合`window.location.search`
 * @function getUrlSearch
 * @param {object} obj - 需要转换的对象
 * @returns {string} 返回结果符合`window.location.search`
 * @author liukun <919590347@qq.com>
 * @example
 * import { getUrlSearch } from '@wont/utils'
 * getUrlSearch({a:'1',b:'2'})  // a=1&b=2'
 */
 
export const getUrlSearch = (obj: Record<string, string>): string => {
  const searchParams = new URLSearchParams(obj)
  return searchParams.toString()
}