Common modules and functions used and shared amongst various projects
  • TypeScript 100%
Find a file
2026-04-11 00:13:25 +00:00
.forgejo/workflows Use dynamic .npmrc file 2026-04-11 00:12:51 +00:00
__tests__ Add unit tests for Fields, isEmailValid, isPasswordValid, and LocalStorage functionalities 2026-04-10 21:35:12 +00:00
src Simplify regex usage in isEmailValid function 2026-04-10 21:34:08 +00:00
.editorconfig First commit 2026-04-10 20:17:59 +00:00
.gitattributes First commit 2026-04-10 20:17:59 +00:00
.gitignore Use dynamic .npmrc file 2026-04-11 00:12:51 +00:00
.npmrc.example Use dynamic .npmrc file 2026-04-11 00:12:51 +00:00
AGENTS.md Add CI workflow for publishing and update npm configuration 2026-04-10 22:10:42 +00:00
package.json chore: release 0.0.9 [skip ci] 2026-04-11 00:13:25 +00:00
README.md Change section title 2026-04-10 23:23:03 +00:00
tsconfig.json Fix indentation in tsconfig.json for improved readability 2026-04-10 21:38:35 +00:00
vitest.config.ts Add and setup vitest 2026-04-10 21:34:57 +00:00
yarn.lock Add CI workflow for publishing and update npm configuration 2026-04-10 22:10:42 +00:00

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