https://github.com/falsy/lightkit
A lightweight collection of commonly used utility functions for everyday JavaScript development.
https://github.com/falsy/lightkit
typescript utility-library
Last synced: 18 days ago
JSON representation
A lightweight collection of commonly used utility functions for everyday JavaScript development.
- Host: GitHub
- URL: https://github.com/falsy/lightkit
- Owner: falsy
- License: unlicense
- Created: 2024-08-24T07:48:07.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-03-04T03:34:10.000Z (3 months ago)
- Last Synced: 2025-05-11T12:57:00.099Z (23 days ago)
- Topics: typescript, utility-library
- Language: TypeScript
- Homepage: https://npmjs.com/package/lightkit
- Size: 271 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LightKit
  
This is a small and lightweight utility library that brings together commonly used functions during development. While there are already many major and excellent libraries available, they often include a lot of unused methods. Therefore, we are developing this library by focusing on only the essential features, keeping it lightweight.
## Install
```shell
$ npm install lightkit
```## Array
### multiFilter
Filters an array using multiple filter functions and returns the filtered results in separate arrays.
```ts
import { multiFilter } from "lightkit"const array = [1, 2, 3, 4, 5, 6]
const filters = [
(n) => n % 2 === 0, // Filter even numbers
(n) => n % 2 !== 0 // Filter odd numbers
]
const result = multiFilter(array, filters)console.log(result)
// [[2, 4, 6], [1, 3, 5]]
```## Date
### Constructor
Initializes the class with a given date value or the current date if no value is provided.
> The `LDate` class also supports the `"YYYY-MM-DD HH:MM:SS"` format as a local date.
```ts
import { LDate } from "lightkit"const instance1 = new LDate()
// Initializes with the current date and time.
const instance2 = new LDate(1629918000000)
// Initializes with a timestamp.
const instance3 = new LDate("2023-08-27T10:15:00Z")
// Initializes with a valid date string.
const instance4 = new LDate("2023-08-27 10:15:00")
// Initializes with a custom date string.
const instance5 = new LDate(new Date())
// Initializes with a Date object.
```### getDate
Retrieves the current date.
```ts
import { LDate } from "lightkit"const dateString = "2023-08-27T10:15:00Z"
const dateTime = new Date(dateString).getTime()
const lDateTime = new LDate(dateString).getDate().getTime()console.log(new LDate(dateString).getDate() instanceof Date) // true
console.log(dateTime === lDateTime) // true
```### getDateParts
Extracts various date and time properties from the Date object.
```ts
import { LDate } from "lightkit"const dateString = "2023-08-27 15:30:45"
const dateProperties = new LDate(dateString).getDateParts("en")console.log(dateProperties)
// {
// year: '2023',
// month: '08',
// day: '27',
// hour: '15',
// minute: '30',
// second: '45',
// yearMonthDay: '2023-08-27',
// yearMonth: '2023-08',
// monthDay: '08-27',
// hourMinuteSecond: '15:30:45',
// hourMinute: '15:30',
// dayOfWeek: 0,
// dayOfWeekLong: 'Sunday',
// dayOfWeekShort: 'Sun',
// longTime: 1693117845000
// }
```### differenceIn
Calculates the difference between the current date and the provided date in the specified unit.
```ts
import { LDate } from "lightkit"const lDate = new LDate("2023-01-01T00:00:00Z")
const targetDate = new Date("2024-01-01T00:00:00Z")const diffInYears = lDate.differenceIn(targetDate, "year")
console.log(diffInYears) // 1const diffInMonths = lDate.differenceIn(targetDate, "month")
console.log(diffInMonths) // 12const diffInDays = lDate.differenceIn(targetDate, "day")
console.log(diffInDays) // 365const diffInHours = lDate.differenceIn(targetDate, "hour")
console.log(diffInHours) // 8760const diffInMinutes = lDate.differenceIn(targetDate, "minute")
console.log(diffInMinutes) // 525600const diffInSeconds = lDate.differenceIn(targetDate, "second")
console.log(diffInSeconds) // 31536000
```