function stringify()

in translate/src/context/Location.tsx [125:173]


function stringify(prev: Location, next: string | Partial<Location>) {
  if (typeof next === 'string') {
    return next;
  }

  const locale = next.locale || prev.locale;
  const project = next.project || prev.project;
  const resource = next.resource || prev.resource;
  const pathname = `/${locale}/${project}/${resource}/`;

  const params = new URLSearchParams();
  if (next.list) {
    params.set('list', next.list.join(','));
  } else {
    let keepList = !('list' in next);
    for (const key of [
      'search',
      'status',
      'extra',
      'search_identifiers',
      'search_exclude_source_strings',
      'search_rejected_translations',
      'search_match_case',
      'search_match_whole_word',
      'tag',
      'author',
      'time',
      'reviewer',
      'review_time',
      'exclude_self_reviewed',
    ] as const) {
      const value = key in next ? next[key] : prev[key];
      if (value) {
        params.set(key, String(value));
        keepList &&= false;
      }
    }
    if (keepList && prev.list) {
      params.set('list', prev.list.join(','));
    }
  }
  const entity = 'entity' in next ? next.entity : prev.entity;
  if (entity) {
    params.set('string', String(entity));
  }

  const ps = String(params).replace(/%2C/g, ',');
  return ps ? `${pathname}?${ps}` : pathname;
}