🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

predict-data-types

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

predict-data-types

A lightweight, zero-dependency npm package that predicts data types for comma-separated values, including JSON objects, and validates URLs, phone numbers, email addresses, IP addresses, colors, percentages, and currency within string values.

Source
npmnpm
Version
1.5.0
Version published
Weekly downloads
20
150%
Maintainers
1
Weekly downloads
 
Created
Source

Predict Data Types

npm version License: MIT

A lightweight, zero-dependency npm package that automatically predicts data types for comma-separated values. Supports 14 data types including primitives, URLs, emails, UUIDs, dates, IP addresses, colors, percentages, and currency.

Features

  • Automatic detection of 14 data types
  • CSV parsing with optional headers
  • TypeScript definitions included
  • Zero dependencies - completely standalone
  • Comprehensive test coverage
  • Optimized regex patterns

Installation

npm install predict-data-types

Supported Data Types

TypeExamples
string'John', 'Hello World'
number42, 3.14, -17, 1e10
booleantrue, false, yes, no
emailuser@example.com
phone555-555-5555, (555) 555-5555
urlhttps://example.com
uuid550e8400-e29b-41d4-a716-446655440000
date2023-12-31, 31/12/2023
ip192.168.1.1, 2001:0db8::1
color#FF0000, #fff
percentage50%, -25%
currency$100, €50.99
array[1, 2, 3]
object{"name": "John"}

Usage

Basic Example

const predictDataTypes = require("predict-data-types");

const text = "John, 30, true, john@example.com, 2023-01-01";
const types = predictDataTypes(text);

console.log(types);
// {
//   'John': 'string',
//   '30': 'number',
//   'true': 'boolean',
//   'john@example.com': 'email',
//   '2023-01-01': 'date'
// }

CSV with Headers

const csvData = `name,age,active,email
John,30,true,john@example.com`;

const types = predictDataTypes(csvData, true);
// {
//   'name': 'string',
//   'age': 'number',
//   'active': 'boolean',
//   'email': 'email'
// }

Complex Data

const data = "192.168.1.1, #FF0000, 50%, $100, 2023-12-31";
const types = predictDataTypes(data);
// {
//   '192.168.1.1': 'ip',
//   '#FF0000': 'color',
//   '50%': 'percentage',
//   '$100': 'currency',
//   '2023-12-31': 'date'
// }

API

predictDataTypes(input, firstRowIsHeader)

Parameters:

  • input (string): Comma-separated string to analyze
  • firstRowIsHeader (boolean): Treat first row as headers (default: false)

Returns: Object mapping field names/values to their data types

Throws: Error if input is null, undefined, or not a string

Development

npm test              # Run tests
npm run test:coverage # Run tests with coverage
npm run lint          # Check code quality
npm run lint:fix      # Fix lint issues

License

MIT License - see LICENSE file for details.

Contributing

See CONTRIBUTING.md for contribution guidelines.

Author: Melih Birim

Keywords

predict

FAQs

Package last updated on 14 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts