Skip to content

Main content

Numeric Dataset Parser Source Code

Browse the implementation files for Numeric Dataset Parser.
@tool.io/tools/parse/numeric-dataset source ↗
tool.ts typescript
import {
	normalizeNumericDataset as normalizePortableNumericDataset,
	parseFiniteNumberList as parsePortableFiniteNumberList,
	parseNumericDataset as parsePortableNumericDataset,
	type EmptyEntryPolicy
} from '@tool.io/tools/parse/numeric-dataset';

export type { EmptyEntryPolicy };

export const parseNumericDataset = (
	input: unknown,
	emptyEntryPolicyInput: unknown = 'reject'
): number[] | null => {
	const result = parsePortableNumericDataset({
		emptyEntryPolicy: emptyEntryPolicyInput,
		value: input
	});

	return result.ok ? [...result.output.values] : null;
};

export const parseFiniteNumberList = (
	input: unknown
): number[] | null => {
	const values = parsePortableFiniteNumberList(input);
	return values === null ? null : [...values];
};

export const normalizeNumericDataset = (
	input: unknown,
	emptyEntryPolicyInput: unknown = 'reject'
): string => {
	return normalizePortableNumericDataset(
		input,
		emptyEntryPolicyInput
	);
};

export const Tool: TypeTool = {
	name: 'Numeric Dataset Parser',
	slug: 'parse/numeric-dataset',
	intro: 'Parse and normalize a list of finite numeric values.',
	tool: normalizeNumericDataset,
	i: [
		{
			example: '1, 2, 3, 4, 5',
			help: 'Enter finite numbers separated by commas, spaces, semicolons, tabs, or new lines.',
			label: 'Dataset',
			placeholder: 'Enter numeric values',
			render: 'textarea',
			type: 'text'
		},
		{
			example: 'reject',
			label: 'Empty entries',
			options: [
				{ text: 'Reject empty entries', value: 'reject' },
				{ text: 'Ignore empty entries', value: 'ignore' }
			],
			placeholder: 'Choose how to handle empty entries',
			type: 'select',
			value: 'reject'
		}
	],
	o: [
		{
			example: '1,2,3,4,5',
			help: 'Normalized comma-separated finite numbers.',
			label: 'Normalized Dataset',
			placeholder: 'Normalized dataset will appear here...',
			render: 'textarea',
			type: 'text'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Numeric Dataset Parser.

References

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

Similar or alternative tools