'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
 
Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.getPath = getPath;
exports.default = void 0;
 
function _prettyFormat() {
  const data = _interopRequireDefault(require('pretty-format'));
 
  _prettyFormat = function () {
    return data;
  };
 
  return data;
}
 
function _jestGetType() {
  const data = require('jest-get-type');
 
  _jestGetType = function () {
    return data;
  };
 
  return data;
}
 
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {default: obj};
}
 
/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */
var _default = (title, headings, row) => {
  const table = convertRowToTable(row, headings);
  const templates = convertTableToTemplates(table, headings);
  return templates.map(template => ({
    arguments: [template],
    title: interpolate(title, template)
  }));
};
 
exports.default = _default;
 
const convertRowToTable = (row, headings) =>
  Array.from({
    length: row.length / headings.length
  }).map((_, index) =>
    row.slice(
      index * headings.length,
      index * headings.length + headings.length
    )
  );
 
const convertTableToTemplates = (table, headings) =>
  table.map(row =>
    row.reduce(
      (acc, value, index) =>
        Object.assign(acc, {
          [headings[index]]: value
        }),
      {}
    )
  );
 
const interpolate = (title, template) =>
  Object.keys(template)
    .reduce(getMatchingKeyPaths(title), []) // aka flatMap
    .reduce(replaceKeyPathWithValue(template), title);
 
const getMatchingKeyPaths = title => (matches, key) =>
  matches.concat(title.match(new RegExp(`\\$${key}[\\.\\w]*`, 'g')) || []);
 
const replaceKeyPathWithValue = template => (title, match) => {
  const keyPath = match.replace('$', '').split('.');
  const value = getPath(template, keyPath);
 
  if ((0, _jestGetType().isPrimitive)(value)) {
    return title.replace(match, String(value));
  }
 
  return title.replace(
    match,
    (0, _prettyFormat().default)(value, {
      maxDepth: 1,
      min: true
    })
  );
};
/* eslint import/export: 0*/
 
function getPath(template, [head, ...tail]) {
  if (!head || !template.hasOwnProperty || !template.hasOwnProperty(head))
    return template;
  return getPath(template[head], tail);
}