PageSourceSearch

https://www.kintetsu-g-hd.co.jp/common-hd/microcms/functions/get-values-by-key.js

js kintetsu-g-hd.co.jp collected 2026-10-02 04:13:45 UTC 963 bytes, 19 lines download raw bytes

1/**
2 * ----------------------------------------------
3 * CATEGORYのkeyから指定したプロパティを取得する
4 * --
5 * @param {Array} categories - カテゴリ配列または二次元配列
6 * @param {string} seg - 検索するキー
7 * @param {Object} options - オプション
8 * @param {string} [options.prop='value'] - 取得するプロパティ名('value' や 'seg_name' 等)
9 * @param {boolean} [options.unique=false] - 重複を除外するか
10 * @return {Array}
11 * ----------------------------------------------
12 */
13export function getValuesByKey(categories, seg, { prop = 'value', unique = false } = {}) {
14  const flat = typeof categories.flat === 'function' ? categories.flat() : categories.reduce((a, b) => a.concat(b), []);
15  const values = flat
16    .filter(item => item && item.seg_name === seg && Object.prototype.hasOwnProperty.call(item, prop))
17    .map(item => item[prop]);
18  return unique ? Array.from(new Set(values)) : values;
19}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.