0.0.1 • Published 1 year ago
@aid-kit/object v0.0.1
Aid Kit - Object
@aid-kit/object
is a lightweight package that provides simple object helpers.
Features
- Easy to use: The package provides simple functions for common object operations.
- TypeScript: The package is written in TypeScript and provides type definitions.
- Lightweight: The package is lightweight and has no dependencies.
Installation
npm install @aid-kit/object
pnpm add @aid-kit/object
yarn add @aid-kit/object
bun add @aid-kit/object
Usage
import { removeDuplicates, flatten, deepClone, deepMerge } from "@aid-kit/object"
// Remove duplicates from an array
const arr = [1, 2, 2, 3]
const uniqueArr = removeDuplicates(arr)
console.log(uniqueArr) // [1, 2, 3]
// Flatten an array
const arr = [1, [2, [3, 4], 5]]
const flattenedArr = flatten(arr)
console.log(flattenedArr) // [1, 2, 3, 4, 5]
// Deep clone an object
const obj = { a: 1, b: { c: 2 } }
const clone = deepClone(obj)
clone.b.c = 3
console.log(obj.b.c) // 2
console.log(clone.b.c) // 3
// Deep merge two objects
const target = { a: 1, b: { c: 2 } }
const source = { b: { d: 3 } }
const merged = deepMerge(target, source)
console.log(merged) // { a: 1, b: { c: 2, d: 3 } }
API Reference
removeDuplicates(arr)
Removes duplicates from an array.
arr
(any[]): The array to remove duplicates from.
removeDuplicates([1, 2, 2, 3]) // [1, 2, 3]
flatten(arr)
Flattens an array.
arr
(any[]): The array to flatten.
flatten([1, [2, [3, 4], 5]]) // [1, 2, 3, 4, 5]
deepClone(obj)
Deep clones an object.
obj
(object): The object to deep clone.
const obj = { a: 1, b: { c: 2 } }
const clone = deepClone(obj)
clone.b.c = 3
console.log(obj.b.c) // 2
console.log(clone.b.c) // 3
deepMerge(target, source)
Deep merges two objects.
target
(object): The target object.source
(object): The source object.
const target = { a: 1, b: { c: 2 } }
const source = { b: { d: 3 } }
const merged = deepMerge(target, source) // { a: 1, b: { c: 2, d: 3 } }
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request. Here are some ways you can contribute:
- Bug reports: If you find any bugs or unexpected behavior, please open an issue describing the problem.
- Feature requests: If you have ideas for new features or improvements, feel free to suggest them by opening an issue.
- Code contributions: Contributions to the codebase via pull requests are highly appreciated. Before submitting a pull request, please make sure to follow the contribution guidelines below.
Contribution Guidelines
- Fork the repository and clone it to your local machine.
- Create a new branch for your feature/fix:
git checkout -b feature-name
. - Make changes and test them thoroughly.
- Ensure that your code follows the existing code style and conventions.
- Update the README and documentation if necessary.
- Commit your changes with descriptive commit messages.
- Push your branch to your fork:
git push origin feature-name
. - Open a pull request to the
main
branch of the original repository.
Thank you for contributing to @aid-kit/object
!
License
This project is under the MIT License - see the LICENSE file for details.
0.0.1
1 year ago