Skip to content

feat: add duration detector#30

Open
shozabali06 wants to merge 1 commit intomelihbirim:mainfrom
shozabali06:feature/add-duration-detection
Open

feat: add duration detector#30
shozabali06 wants to merge 1 commit intomelihbirim:mainfrom
shozabali06:feature/add-duration-detection

Conversation

@shozabali06
Copy link
Copy Markdown

Pull Request

Description

Adds duration detection feature

Related Issue

Add Duration/Time Interval Detector #25
Fixes #

Changes Made

  • Added isDuration() function in index.js
  • Added tests in test/index.spec.js
  • Updated index.d.ts with TypeScript definitions
  • Updated README.md with examples and counts

Checklist

Required (PR will not be merged without these):

  • [ x ] ✅ Synced with latest main branch (git rebase main)
  • [ x ] ✅ All tests pass (npm test)
  • [ x ] ✅ Linting passes (npm run lint)
  • [ x ] ✅ README.md updated with:
    • [ x ] Data type added to supported types list
    • [ x ] Test count updated
    • [ x ] Usage example added
  • [ x ] ✅ TypeScript definitions added in index.d.ts
  • [ x ] ✅ JSDoc documentation added for new functions

Code Quality:

  • [ x ] Followed conventional commit format (feat:, fix:, style:, etc.)
  • [ x ] Used single quotes (') not double quotes (")
  • [ x ] No console.log statements in code
  • [ x ] Functions added at the end of file (minimizes conflicts)
  • [ x ] Test cases added at the end of test file
  • [ x ] Pre-commit hook ran automatically (auto-fixed linting)

Test Results

> predict-data-types@1.7.1 test
> mocha test



  DataTypes constants
    ✔ should export all type constants

  Formats constants
    ✔ should export all format constants

  predictDataTypes
    ✔ should predict data types for string and url
    ✔ should predict data types with numbers and date
    ✔ should predict data types for strings with phone numbers
    ✔ should predict data types for arrays
    ✔ should predict data types for JSON objects
    Input validation and edge cases
      ✔ should handle null input
      ✔ should handle undefined input
      ✔ should handle empty string input
      ✔ should handle whitespace-only string input
      ✔ should handle non-string input types
      ✔ should handle single character input
      ✔ should handle missing header fields gracefully
      ✔ should handle more data fields than header fields
    UUID detection
      ✔ should correctly detect valid UUIDs
      ✔ should correctly detect multiple UUIDs
      ✔ should not detect invalid UUIDs
    Boolean detection
      ✔ should detect various true/false representations
      ✔ should detect comprehensive boolean representations
      ✔ should not detect partial boolean words
    Email detection
      ✔ should detect valid email addresses
      ✔ should not detect invalid email addresses
    Date detection
      ✔ should detect various date formats
      ✔ should detect dates with month names
      ✔ should detect dates with time and month names
      ✔ should not detect invalid dates
    Number detection
      ✔ should detect various number formats
      ✔ should not detect invalid numbers
    Tokenization edge cases
      ✔ should handle nested objects and arrays
      ✔ should handle quoted strings with commas
      ✔ should handle strings with escaped quotes
    Header mode functionality
      ✔ should handle single line input in header mode
      ✔ should handle multi-line input with headers
      ✔ should handle mismatched header and data columns
    IP address detection
      ✔ should detect valid IPv4 addresses
      ✔ should detect valid IPv6 addresses
      ✔ should not detect invalid IP addresses
    MAC address detection
      ✔ should detect valid MAC addresses with colon separators
      ✔ should detect valid MAC addresses with hyphen separators
      ✔ should not detect invalid MAC addresses
    Hex color detection
      ✔ should detect valid hex colors
      ✔ should not detect invalid hex colors
    Percentage detection
      ✔ should detect valid percentages
      ✔ should not detect invalid percentages
    Currency detection
      ✔ should detect valid currency amounts
      ✔ should detect currency with symbol after amount
      ✔ should not detect invalid currency formats
    Hashtag detection
      ✔ should detect valid hashtags
      ✔ should not detect invalid hashtags
    Duration detection
      ✔ should detect valid durations with seconds
      ✔ should detect valid durations with minutes
      ✔ should detect valid durations with hours
      ✔ should detect valid durations with days
      ✔ should detect valid durations with multiple units
      ✔ should detect valid durations with decimal numbers
      ✔ should detect valid durations with singular and plural forms
      ✔ should not detect invalid durations
      ✔ should not detect durations without units
      ✔ should not detect durations with invalid unit names
      ✔ should detect duration through infer function
      ✔ should detect duration in array of values
      ✔ should detect duration in object schema
    infer
      ✔ should infer type from single string value
      ✔ should detect social media mentions/usernames
      ✔ should detect cron expressions
      ✔ should infer type from array of values
      ✔ should infer schema from single object
      ✔ should infer schema from array of objects
      ✔ should handle objects with different fields
      ✔ should handle various data types in objects
      ✔ should handle null and undefined values in objects
      ✔ should handle empty array
      ✔ should convert non-string values to strings before type detection
      ✔ should throw error for invalid input
      ✔ should infer hashtag from single value
      ✔ should infer hashtag from array of values
      ✔ should not infer hashtag when mixed with non-hashtag
      ✔ should prefer hex color over hashtag for 3-char ambiguous values by default
      ✔ should prefer hashtag over 3-char hex when option is enabled
      ✔ should keep non-ambiguous values unchanged with option
    JSON Schema format
      ✔ should return JSON Schema for single object with jsonschema format
      ✔ should return JSON Schema for array of objects with jsonschema format
      ✔ should include format for special types
      ✔ should include pattern for types without standard format
      ✔ should return simple schema by default (no format parameter)
      ✔ should return simple schema when format is Formats.NONE
      ✔ should include pattern for hashtag in JSON Schema


  88 passing (126ms)

Avoiding Conflicts

  • [ x ] I have rebased on the latest main branch before creating this PR
  • [ x ] I understand that if conflicts occur, I need to resolve them by rebasing again

Thank you for contributing! 🎉

See CONTRIBUTING.md for detailed guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant