Options
All
  • Public
  • Public/Protected
  • All
Menu

External module @tomato-js/path

Index

Functions

getSearch

  • getSearch(url?: string): string
  • 获取url中的search字符串

    脚本举例

      import { getSearch } from '@tomato-js/path';
      const search = parse()//默认使用window.location.href;
      const search2 = parse("https://www.baidu.com?a=123&e=f")//?a=123&e=f;

    Parameters

    • Default value url: string = window.location.href

      待解析的url

    Returns string

    search字符串

merge

  • merge(from: string, to: string): string
  • 将form和to的queryString进行merge合并到to

    脚本举例

      import { merge } from '@tomato-js/path';
      merge("https://tomato-js.github.io?a=b&c=d", "https://www.baidu.com?a=123&e=f");
      //https://www.baidu.com?a=123&c=d&e=f

    Parameters

    • from: string

      解析的url

    • to: string

      待合并的url

    Returns string

    合并后的url

parse

  • parse(str: string, options?: ParseOptions): null | {}
  • 解析search字符串

    脚本举例

      import { parse } from '@tomato-js/path';
      const queryObj = parse()//默认使用window.location.search;
      const queryObj2 = parse('?a=123&b=456')//{a:'123',b:'456'};
      const queryObj3 = parse('a=123&b=456')//{a:'123',b:'456'};

    Parameters

    • str: string

      待解析的字符串

    • Default value options: ParseOptions = {encode: true}

      其他解析参数

    Returns null | {}

    解析完成的对象

stringify

  • stringify(queryObj: ObjectType<string | number>, options?: StringifyOptions): string
  • 解析对象为query字符串

    脚本举例

      import { stringify } from '@tomato-js/path';
      const queryStr = stringify({
        queryKey: "this is queryA"
      });
      //queryKey=this%20is%20queryA

    Parameters

    • queryObj: ObjectType<string | number>

      待解析的对象

    • Default value options: StringifyOptions = {encode: true}

      其他解析参数

    Returns string

    解析完成的query字符串

Generated using TypeDoc