Skip to content

Main content

Numeric Matrix Parser Source Code

Browse the implementation files for Numeric Matrix Parser.
@tool.io/tools/parse/matrix source ↗
tool.ts typescript
import {
	parseNumericMatrix,
	type NumericMatrix
} from '@tool.io/tools/parse/matrix';

export { parseNumericMatrix, type NumericMatrix };

export const normalizeMatrix = (input: unknown): string => {
	const matrix = parseNumericMatrix(input);
	return matrix === null ? '' : JSON.stringify(matrix);
};

export const Tool: TypeTool = {
	name: 'Numeric Matrix Parser',
	slug: 'parse/matrix',
	intro:
		'Parse a rectangular numeric matrix from JSON or rows of comma- or space-separated values.',
	tool: normalizeMatrix,
	i: [
		{
			example: '1, 2, 3\n4, 5, 6',
			label: 'Matrix',
			placeholder: 'Enter matrix rows',
			render: 'textarea',
			type: 'text'
		}
	],
	o: [
		{
			example:
				'{"columns":3,"kind":"matrix/number","rows":2,"values":[[1,2,3],[4,5,6]],"version":1}',
			label: 'Parsed Matrix',
			placeholder: 'Parsed matrix will appear here...',
			render: 'textarea',
			type: 'text'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Numeric Matrix Parser.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools