New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

is-only

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-only

Lightweight TypeScript validation library with fluent API

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

IsOnly - validator

Lightweight TypeScript validation library with fluent API.

API Reference

isOnly.String(val)

Validates non-empty strings.

Returns true for:

  • 'hello'
  • ' test '

Returns false for:

  • '' (empty string)
  • ' ' (only spaces)
  • null, undefined, different types

isOnly.Number(val)

Validates valid numbers (excluding zero and NaN).

Returns true for:

  • 1
  • -5
  • 3.14

Returns false for:

  • '123' (string)
  • 0 (zero)
  • NaN (not a number)
  • null, undefined, different types

isOnly.Boolean(val)

Validates boolean true values only.

Returns true for:

  • true

Returns false for:

  • false
  • 1, 0, 'true', null, undefined, different types

isOnly.Object(val)

Validates non-empty objects (excluding arrays).

Returns true for:

  • {a: 1}
  • { key: 'value' }

Returns false for:

  • {} (empty object)
  • [] (array)
  • null, undefined, 'string', 0, different types

isOnly.Array(val)

Validates non-empty arrays.

Returns true for:

  • [1, 2, 3]
  • ['a']

Returns false for:

  • [] (empty array)
  • '' (empty string)
  • ' ' (only spaces)
  • null, undefined, different types

isOnly.Failure(val)

Returns true for values that fail all other validations.

Returns true for:

  • null, undefined
  • '', ' '
  • 0, false
  • {}, []

Returns false for:

  • Any value that passes String, Number, Boolean, Object, or Array validation (non-empty values)

Fluent API Methods

Each validator returns a ValidationResult object with additional methods:

Methods

  • .value - Returns validated value or null
  • .empty - Inverted validation result
  • .throw() - Throws error on failure, returns value on success

Keywords

validation

FAQs

Package last updated on 13 Jun 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