@wt/common (0.0.9)

Published 2026-04-11 02:14:20 +02:00 by wess in wesnetech/common-pkg

Installation

@wt:registry=
npm install @wt/common@0.0.9
"@wt/common": "0.0.9"

About this package

Common Modules

Common modules and functions used and shared amongst various projects

Installation

yarn add @wt/common

# or

npm install @wt/common

Usage

To use the validateEmail function, just import it from the package and use as follows:

import { validateEmail } from '@wt/common';

console.log(validateEmail('hellowesnetech.com'));

// false

Documentation

Fields Namespace

The Fields namespace contains methods for validating values, especially form input.

Methods
  • isEmpty(value: Value): boolean

    • Checks if a value is empty.
    • Parameters:
      • value: Value - The value to check.
    • Returns: true for empty strings, and null or undefined values.
  • isAnyEmpty(values: Array<Value>): boolean

    • Checks if any of the list items is empty.
    • Parameters:
      • values: Array<Value> - The list of values to be checked.
    • Returns: true if any value is empty.
  • isNotEmpty(value: Value): boolean

    • Checks if a value is not empty.
    • Parameters:
      • value: Value - The value to check.
    • Returns: true if the value is not empty.
  • isObjectNotEmpty<T extends object>(data: T): boolean

    • Checks if an object is not empty by filtering out falsy values.
    • Parameters:
      • data: T - The object to check.
    • Returns: true if the object is not empty.
  • isURL(value: string | null | undefined): boolean

    • Checks if the value is a URL.
    • Parameters:
      • value: string | null | undefined - The value to check.
    • Returns: true if the value is a valid URL.
  • parseBoolean(value: string | number | null | undefined, defaultValue = false): boolean

    • Parses a value as boolean.
    • Parameters:
      • value: string | number | null | undefined - The value to check.
      • defaultValue: boolean - The default value to return for an invalid value.
    • Returns: The parsed boolean value.
  • parseNumber(value: string | null | undefined, defaultValue = 0): number

    • Parses a value to a number.
    • Parameters:
      • value: string | null | undefined - The value to be parsed.
      • defaultValue: number - The default value to return for an invalid value.
    • Returns: The parsed number value.
  • available(value: Value): Value | undefined

    • Checks if a value is available.
    • Parameters:
      • value: Value - The value to check.
    • Returns: undefined if the value is empty (in other words, not available). Otherwise, it returns the input value itself.
  • update(current: FieldValue, previous: FieldValue): FieldValue | undefined

    • Compares current and previous values, returning the current value if it has changed.
    • Parameters:
      • current: FieldValue - The current value of a field that is being updated.
      • previous: FieldValue - The previous value of a field that is being updated.
    • Returns: Either undefined, or the current value if it has changed.

API References

Value Type

The Value type is a union type that can be one of the following:

  • string
  • number
  • Date
  • null
  • undefined

FieldValue Type

The FieldValue type is a union type that can be one of the following:

  • Value
  • boolean

Dependencies

Development dependencies

ID Version
@types/node ^25.6.0
rimraf ^6.0.0
typescript ^6.0.2
vitest ^3.1.1
Details
npm
2026-04-11 02:14:20 +02:00
5
MIT
latest
3.6 KiB
Assets (1)
Versions (2) View all
0.0.9 2026-04-11
0.0.7 2026-04-11