Utils#

deprecate(dep, sub, as_of)#

Log deprecation warning.

Arguments
  • dep (string()) – Deprecated object

  • sub (string()) – Substitute for deprecated object.

  • as_of (string()) – Version when deprecated object gets removed.


uuid4()#

Generate uuid 4.

Returns

string – UUID string.


set_default(ob, name, val)#

Set property on object with default value if property is undefined.

Arguments
  • ob (Object()) – Object to set property if undefined.

  • name (string()) – Property name.

  • val (*()) – Default value to set for property.

Returns

* – Actual value.


parse_url(url)#

Parse URL without query from string:

>> ts.parse_url('https://tld.com/path?param=value');
<- 'https://tld.com/path'
Arguments
  • url (string()) – URL to parse.

Returns

string – URL without query.


parse_query(url, as_string)#

Parse query parameters from URL string.

By default, the query parameters are returned as object:

>> ts.parse_query('http://tld.com?param=value');
<- { param: 'value' }

The query parameters can be parsed as string by passing true to parse_query:

>> ts.parse_query('http://tld.com?param=value', true);
<- '?param=value'
Arguments
  • url (string()) – URL to parse.

  • as_string (boolean()) – Flag whether to return query as string.

Returns

Object|string – Query parameters.


parse_path(url, include_query)#

Parse relative path from URL string.

By default, the query is excluded:

>> ts.parse_path('http://tld.com/some/path?param=value');
<- '/some/path'

The query can be included by passing true to parse_path:

>> ts.parse_path('http://tld.com/some/path?param=value', true);
<- '/some/path?param=value'
Arguments
  • url (string()) – URL to parse.

  • include_query (boolean()) – Flag whether to include query.

Returns

string – Path with or without query.