Created
February 25, 2020 13:14
-
-
Save guchimon99/9e6e2ba1938f1f8b4b03d810dde5d6d1 to your computer and use it in GitHub Desktop.
Yahoo!ショッピングの商品登録時のバリエーションのサブコードの生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const baseCode = 'code' | |
| const options = [ | |
| { | |
| label: 'カラー', | |
| code: 'c', | |
| items: [ | |
| {label: 'ブラック', code: 'black'}, | |
| {label: 'ホワイト', code: 'white'}, | |
| {label: 'ベージュ', code: 'beige'}, | |
| {label: 'オレンジ', code: 'orange'}, | |
| {label: 'パープル', code: 'purple'}, | |
| {label: 'グリーン', code: 'green'}, | |
| {label: 'カーキ', code: 'khaki'}, | |
| {label: 'イエロー', code: 'yellow'}, | |
| {label: 'ネイビー', code: 'navy'}, | |
| ] | |
| }, { | |
| label: 'サイズ', | |
| code: 's', | |
| items: [ | |
| {label: 'S', code: 's'}, | |
| {label: 'M', code: 'm'}, | |
| {label: 'L', code: 'l'}, | |
| ] | |
| } | |
| ] | |
| const data = options | |
| .reduce((rows, option) => | |
| rows.reduce((rows, row) => | |
| [...rows, ...option.items.map(item => ({ | |
| labels: [...row.labels, `${option.label}:${item.label}`], | |
| codes: [...row.codes, `${option.code}-${item.code}`], | |
| }))] | |
| , []) | |
| , [{ labels:[], codes: [baseCode] }]) | |
| .map(({labels, codes}) => `${labels.join('#')}=${codes.join('-')}`) | |
| .join('&') | |
| console.log(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| カラー:ブラック#サイズ:S=code-color-black-size-s&カラー:ブラック#サイズ:M=code-color-black-size-m&カラー:ブラック#サイズ:L=code-color-black-size-l&カラー:ホワイト#サイズ:S=code-color-white-size-s&カラー:ホワイト#サイズ:M=code-color-white-size-m&カラー:ホワイト#サイズ:L=code-color-white-size-l&カラー:ベージュ#サイズ:S=code-color-beige-size-s&カラー:ベージュ#サイズ:M=code-color-beige-size-m&カラー:ベージュ#サイズ:L=code-color-beige-size-l&カラー:オレンジ#サイズ:S=code-color-orange-size-s&カラー:オレンジ#サイズ:M=code-color-orange-size-m&カラー:オレンジ#サイズ:L=code-color-orange-size-l&カラー:パープル#サイズ:S=code-color-purple-size-s&カラー:パープル#サイズ:M=code-color-purple-size-m&カラー:パープル#サイズ:L=code-color-purple-size-l&カラー:グリーン#サイズ:S=code-color-green-size-s&カラー:グリーン#サイズ:M=code-color-green-size-m&カラー:グリーン#サイズ:L=code-color-green-size-l&カラー:カーキ#サイズ:S=code-color-khaki-size-s&カラー:カーキ#サイズ:M=code-color-khaki-size-m&カラー:カーキ#サイズ:L=code-color-khaki-size-l&カラー:イエロー#サイズ:S=code-color-yellow-size-s&カラー:イエロー#サイズ:M=code-color-yellow-size-m&カラー:イエロー#サイズ:L=code-color-yellow-size-l&カラー:ネイビー#サイズ:S=code-color-navy-size-s&カラー:ネイビー#サイズ:M=code-color-navy-size-m&カラー:ネイビー#サイズ:L=code-color-navy-size-l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment