helper.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. export function column(value, field) {
  2. if (value === null)
  3. return undefined;
  4. return { type: 'column', value, field };
  5. }
  6. export function inferredColumn(value, field) {
  7. const c = column(value, field);
  8. return Object.assign(Object.assign({}, c), { inferred: true });
  9. }
  10. export function visualColumn(value, field) {
  11. if (value === null)
  12. return undefined;
  13. return { type: 'column', value, field, visual: true };
  14. }
  15. export function nonConstantColumn(value, field) {
  16. const c = column(value, field);
  17. return Object.assign(Object.assign({}, c), { constant: false });
  18. }
  19. export function constant(I, value) {
  20. const array = [];
  21. for (const i of I)
  22. array[i] = value;
  23. return array;
  24. }
  25. export function columnOf(encode, key) {
  26. const channel = encode[key];
  27. if (!channel)
  28. return [null, null];
  29. const { value, field = null } = channel;
  30. return [value, field];
  31. }
  32. export function maybeColumnOf(encode, ...K) {
  33. for (const key of K) {
  34. if (typeof key === 'string') {
  35. const [KV, fv] = columnOf(encode, key);
  36. if (KV !== null)
  37. return [KV, fv];
  38. }
  39. else {
  40. return [key, null];
  41. }
  42. }
  43. return [null, null];
  44. }
  45. export function isObject(d) {
  46. if (d instanceof Date)
  47. return false;
  48. return typeof d === 'object';
  49. }
  50. //# sourceMappingURL=helper.js.map