<commit_before>'use strict';

const { omit, assignObject } = require('../../../../utilities');

// Name shortcuts, e.g. { nFilter: value } -> { f: value }
const addNameShortcuts = function (token) {
  const shortcuts = namesShortcuts
    .filter(({ from }) => token[from] !== undefined)
    .map(({ from, to }) => ({ [to]: token[from] }))
    .reduce(assignObject, {});
  const attrsToRemove = namesShortcuts
    .filter(({ from }) => token[from] !== undefined)
    .map(({ from }) => from);
  return Object.assign({}, omit(token, attrsToRemove), shortcuts);
};

const removeNameShortcuts = function (token) {
  const shortcuts = namesShortcuts
    .filter(({ to }) => token[to] !== undefined)
    .map(({ from, to }) => ({ [from]: token[to] }))
    .reduce(assignObject, {});
  const attrsToRemove = namesShortcuts
    .filter(({ to }) => token[to] !== undefined)
    .map(({ to }) => to);
  return Object.assign({}, omit(token, attrsToRemove), shortcuts);
};

const namesShortcuts = [
  { from: 'nFilter', to: 'f' },
  { from: 'nOrderBy', to: 'o' },
  { from: 'parts', to: 'p' },
];

module.exports = {
  addNameShortcuts,
  removeNameShortcuts,
};<commit_msg>Simplify pagination minify_names<commit_after>'use strict';

const { invert, mapKeys } = require('../../../../utilities');

// Name shortcuts, e.g. { nFilter: value } -> { f: value }
const addNameShortcuts = function (token) {
  return mapKeys(token, (value, attrName) =>
    shortcuts[attrName] || attrName
  );
};

const removeNameShortcuts = function (token) {
  return mapKeys(token, (value, attrName) =>
    reverseShortcuts[attrName] || attrName
  );
};

const shortcuts = {
  nFilter: 'f',
  nOrderBy: 'o',
  parts: 'p',
};

const reverseShortcuts = invert(shortcuts);

module.exports = {
  addNameShortcuts,
  removeNameShortcuts,
};
{'fraction_non_alphanumeric': 0.19523017193566278, 'fraction_numerical': 0.0, 'mean_word_length': 3.823529411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630488', 'n_tokens_mistral': 627, 'n_tokens_neox': 599, 'n_words': 143}