utils 1.0.8
Install from the command line:
Learn more about npm packages
$ npm install @kreattix/utils@1.0.8
Install via package.json:
"@kreattix/utils": "1.0.8"
About this version
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.
$ npm install @kreattix/utils
$ yarn add @kreattix/utils
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.
The function can be called with various types of arguments:
-
Strings and Numbers: Directly passed as class names.
-
Arrays: Recursively processed, allowing nested conditions.
-
Objects: Keys are used as class names if their corresponding values evaluate to
true
.
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'
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.
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]]
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']
Returns the values of the provided object with type safety.
Function Name | Type | Default |
---|---|---|
classnames | string , { [key: string]: boolean } , string[] |
-- |
objectEntries | object |
-- |
objectKeys | object |
-- |
objectValues | object |
-- |
MIT