MCPcopy Index your code
hub / github.com/Lobos/react-ui / toTextValue

Function toTextValue

src/utils/objects.js:36–60  ·  view source on GitHub ↗
(arr, textTpl='{text}', valueTpl='{id}')

Source from the content-addressed store, hash-verified

34}
35
36export function toTextValue (arr, textTpl='{text}', valueTpl='{id}') {
37 if (!arr) {
38 return [];
39 }
40 if (!Array.isArray(arr)) {
41 arr = Object.keys(arr).map((key) => {
42 return {
43 id: key,
44 text: arr[key]
45 };
46 });
47 }
48 arr = arr.map(function (s) {
49 if (typeof s !== 'object') {
50 s = s.toString();
51 return { $text: s, $value: s, $key: hashcode(s) };
52 } else {
53 s.$text = substitute(textTpl, s);
54 s.$value = substitute(valueTpl, s);
55 s.$key = s.id ? s.id : hashcode(`${s.$text}-${s.$value}`);
56 return s;
57 }
58 });
59 return arr;
60}
61
62export function hashcode(obj) {
63 let hash = 0, i, chr, len, str;

Callers 2

formatDataMethod · 0.90
formatDataMethod · 0.90

Calls 2

substituteFunction · 0.90
hashcodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…