1.0.7 • Published 2 months ago

@kreattix/utils v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Kreattix Design Utils

Basic Utility functions for Kreattix Design. As kreattix design don't have their own utilities, we are here to help you. You easily can use this library with kreattix design. It is also usable with vanilla javascript or any javascript framework.

GitHub license npm version

Installation

using npm

$ npm install @kreattix/utils

using yarn

$ yarn add @kreattix/utils

Class Utilities Documentation

classnames Function

The classnames function is a utility designed to conditionally join class names together. It is flexible and accepts multiple types of arguments, including strings, numbers, arrays, and objects. This function is particularly useful in front-end development, where it can dynamically generate a class name string based on certain conditions.

Usage

The function can be called with various types of arguments:

  1. Strings and Numbers: Directly passed as class names.

  2. Arrays: Recursively processed, allowing nested conditions.

  3. Objects: Keys are used as class names if their corresponding values evaluate to true.

Examples

import { classnames } from '@kreattix/utils';

const className = classnames('btn', 'btn-primary');
// Output: 'btn btn-primary'


const className = classnames({
'btn': true,
'btn-primary': true,
'hidden': false,
});
// Output: 'btn btn-primary'


const isActive = true;
const className = classnames('btn', { 'btn-primary': isActive, 'hidden': !isActive }, ['additional-class']);
// Output: 'btn btn-primary additional-class'

Object Utilities Documentation

This documentation provides details on utility functions designed for object manipulation within TypeScript. These utilities ensure type safety when working with the keys, values, and entries of objects.

objectEntries

Returns the entries (key-value pairs) of the provided object with type safety.

import { objectEntries } from '@kreattix/utils';

const user: User = { id: 1, name: 'John Doe' };
const entries = objectEntries(user);
// entries is of type [keyof User, User[keyof User]][], which is [['id', number], ['name', string]]

objectKeys

Returns the keys of the provided object with type safety.

import { objectKeys } from '@kreattix/utils';

const user: User = { id: 1, name: 'John Doe' };
const keys = objectKeys(user);
// keys is of type (keyof User)[], which is ['id', 'name']

objectValues

Returns the values of the provided object with type safety.

Available Functions

Function NameTypeDefault
classnamesstring , { [key: string]: boolean } , string[]--
objectEntriesobject--
objectKeysobject--
objectValuesobject--

License

MIT

1.0.7

2 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago