All files / src/converter/voxel voxelCoordinate.ts

100% Statements 28/28
100% Branches 3/3
100% Functions 3/3
100% Lines 28/28

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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391x 1x 1x         1x             1x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 4x 4x  
import { baseConverter } from '@/converter/baseConverter';
import { xyz2Coords } from '@/functions/convertXYZ/xyz2Coords';
import { xyz2Glyphs } from '@/functions/convertXYZ/xyz2Glyphs';
import type { IConverterMethods } from '@/types/converter';
import type { GalacticOutput } from '@/types/galacticTypes';
import type { GlyphOutput } from '@/types/glyphTypes';
import type { VoxelInput, VoxelCoordinates } from '@/types/voxelTypes';
import { VoxelInputValidator } from '@/validation/voxelInputValidation';
 
/**
 * A converter that takes a Voxel coordinate and returns functions to convert to other portal types.
 * @param input should be of type {@link VoxelCoordinates| VoxelCoordinates}
 * @returns functions defined in {@link IConverterMethods| IConverterMethods}
 */
export const VoxelCoordinate = (input: VoxelInput): Omit<IConverterMethods, 'toVoxel'> => ({
  toGlyph: baseConverter<VoxelInput, GlyphOutput>({
    input,
    inputValidator: VoxelInputValidator,
    converter: (input: VoxelInput) => {
      const result = xyz2Glyphs(input);
      return {
        code: result,
        hexArray: result.split(''),
      };
    },
  }),
  toGalacticCoordinates: baseConverter<VoxelInput, GalacticOutput>({
    input,
    inputValidator: VoxelInputValidator,
    converter: (input: VoxelInput) => {
      const result = xyz2Coords(input);
      return {
        code: result,
        groups: result.split(':'),
      };
    },
  }),
});