All files / src/utils conversion.ts

0% Statements 0/4
100% Branches 1/1
100% Functions 1/1
0% Lines 0/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14                           
/**
 * 文字列や null/undefined を undefined に寄せる。
 * API送信時に「値なしを消したい」ケース向け。
 */
export const emptyToUndef = (v: unknown): any =>
  v === null || v === undefined || v === '' ? undefined : v
 
/**
 * 文字列や undefined を null に寄せる。
 * フォーム入力(未選択や空入力)で null に統一したいケース向け。
 */
export const emptyToNull = (v: unknown): any =>
  v === null || v === undefined || v === '' ? null : v