@wt/common (0.0.7)
Installation
@wt:registry=npm install @wt/common@0.0.7"@wt/common": "0.0.7"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:
truefor empty strings, andnullorundefinedvalues.
-
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:
trueif any value is empty.
-
isNotEmpty(value: Value): boolean- Checks if a value is not empty.
- Parameters:
value: Value- The value to check.
- Returns:
trueif 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:
trueif 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:
trueif 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 invalidvalue.
- 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 invalidvalue.
- Returns: The parsed number value.
-
available(value: Value): Value | undefined- Checks if a value is available.
- Parameters:
value: Value- The value to check.
- Returns:
undefinedif 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 thecurrentvalue if it has changed.
API References
Value Type
The Value type is a union type that can be one of the following:
stringnumberDatenullundefined
FieldValue Type
The FieldValue type is a union type that can be one of the following:
Valueboolean
Dependencies
Development dependencies
| ID | Version |
|---|---|
| @types/node | ^25.6.0 |
| rimraf | ^6.0.0 |
| typescript | ^6.0.2 |
| vitest | ^3.1.1 |