@bikiran/utils 2.2.5 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +507 -98
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/index.ts +20 -0
- package/dist/lib/utils/convertToYears.d.ts +1 -0
- package/dist/lib/utils/convertToYears.js +42 -0
- package/dist/lib/utils/convertToYears.ts +42 -0
- package/dist/lib/utils/date.d.ts +4 -0
- package/dist/lib/utils/date.js +60 -0
- package/dist/lib/utils/date.ts +68 -0
- package/dist/lib/utils/hash.d.ts +1 -0
- package/dist/lib/utils/hash.js +4 -0
- package/dist/lib/utils/hash.ts +5 -0
- package/dist/lib/utils/math.d.ts +4 -0
- package/dist/lib/utils/math.js +23 -0
- package/dist/lib/utils/math.ts +26 -0
- package/dist/lib/utils/show.d.ts +2 -0
- package/dist/lib/utils/show.js +34 -0
- package/dist/lib/utils/show.ts +40 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,173 +1,582 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/@bikiran/utils)
|
|
2
|
-
[](https://www.npmjs.com/package/@bikiran/utils)
|
|
3
|
-
[](https://github.com/bikirandev/bikiran-utils/blob/main/LICENSE)
|
|
4
|
-
[](https://github.com/bikirandev/bikiran-utils/issues)
|
|
5
|
-
[](https://github.com/bikirandev/bikiran-utils/stargazers)
|
|
6
|
-
[](https://github.com/bikirandev/bikiran-utils/commits/main)
|
|
1
|
+
[](https://www.npmjs.com/package/@bikiran/utils)[](https://www.npmjs.com/package/@bikiran/utils)
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@bikiran/utils)[](https://www.npmjs.com/package/@bikiran/utils)
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
[](https://github.com/bikirandev/bikiran-utils/blob/main/LICENSE)[](https://github.com/bikirandev/bikiran-utils/blob/main/LICENSE)
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
[](https://github.com/bikirandev/bikiran-utils/issues)[](https://github.com/bikirandev/bikiran-utils/issues)
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
[](https://github.com/bikirandev/bikiran-utils/stargazers)[](https://github.com/bikirandev/bikiran-utils/stargazers)
|
|
10
|
+
|
|
11
|
+
[](https://github.com/bikirandev/bikiran-utils/commits/main)[](https://github.com/bikirandev/bikiran-utils/commits/main)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# @bikiran/utils## Overview
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
A comprehensive collection of **React components** and **utility functions** specifically developed for modern web applications. This package provides a robust set of UI components, helper functions, and utilities designed to accelerate development while maintaining consistency and performance.A collection of utility components specifically developed for our organization's internal projects. While primarily tailored to our needs, others may find some components useful.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 🌟 Overview⚠️ **Important Note**: This package was optimized for our specific use cases and may not work as expected in all projects. Use with caution.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
A collection of utility components specifically developed for our organization's internal projects. While primarily tailored to our needs, others may find some components useful.## Dependencies
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
⚠️ **Important Note**: This package was optimized for our specific use cases and may not work as expected in all projects. Use with caution.- `clsx`
|
|
15
32
|
|
|
16
|
-
- `clsx`
|
|
17
33
|
- `tailwind-merge`
|
|
18
|
-
- `Next.js`
|
|
19
34
|
|
|
20
|
-
|
|
35
|
+
## ✨ Key Features- `Next.js`
|
|
21
36
|
|
|
22
|
-
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
- **🎨 UI Components**: Pre-built React components with consistent styling## Peer Dependencies
|
|
40
|
+
|
|
41
|
+
- **🛠️ Utility Functions**: Helper functions for common operations
|
|
42
|
+
|
|
43
|
+
- **📱 Responsive Design**: Mobile-first, responsive componentsThe following packages are required to be installed in your project:
|
|
44
|
+
|
|
45
|
+
- **🎯 Theme Integration**: Seamlessly inherits your Tailwind CSS theme
|
|
46
|
+
|
|
47
|
+
- **⚡ Performance Optimized**: Lightweight and efficient components- `react` (^19.1.0)
|
|
48
|
+
|
|
49
|
+
- **📦 TypeScript Support**: Full TypeScript definitions included- `react-dom` (^19.1.0)
|
|
50
|
+
|
|
51
|
+
- **🔧 Configurable**: Highly customizable with sensible defaults- `dayjs` (^1.11.0) - Used for date/time utilities
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## 📦 What's IncludedMake sure to install these peer dependencies in your project:
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### 🧩 UI Components (15)```bash
|
|
60
|
+
|
|
61
|
+
- **Navigation & Layout**: Custom Sidebar, Header components, Project Selectornpm install react react-dom dayjs
|
|
62
|
+
|
|
63
|
+
- **User Interface**: Profile Management, User Info, Tooltip components ```
|
|
64
|
+
|
|
65
|
+
- **Interactive Elements**: Button Wrapper, Currency Selector, Filter Wrapper
|
|
66
|
+
|
|
67
|
+
- **Feedback Components**: Loading states, Page Loading, Cookies popupPerfect! Here's how you can update the **"Available Components"** section so that each component is a clickable item linking to its dedicated documentation page in your GitHub wiki:
|
|
68
|
+
|
|
69
|
+
- **Service Integration**: Services Popup with app listings
|
|
70
|
+
|
|
71
|
+
- **Data Display**: Pagination, Information Tooltip---
|
|
72
|
+
|
|
73
|
+
- **Utility Widgets**: Copy Wrapper for easy content copying
|
|
23
74
|
|
|
24
75
|
## Available Components
|
|
25
76
|
|
|
26
|
-
|
|
77
|
+
### ⚙️ Utility Functions (11+)
|
|
78
|
+
|
|
79
|
+
- **Date & Time**: Date formatting, time calculations with dayjs integrationEach component below links to its own documentation page for detailed usage:
|
|
80
|
+
|
|
81
|
+
- **Text Processing**: String capitalization, copy-to-clipboard functionality
|
|
82
|
+
|
|
83
|
+
- **Data Structures**: Hash generation, mathematical operations1. [Pagination](https://github.com/bikirandev/bikiran-utils/wiki/02.-Pagination)
|
|
84
|
+
|
|
85
|
+
- **Environment**: URL generation, domain management2. [FilterBarWrapper](https://github.com/bikirandev/bikiran-utils/wiki/03.-FilterBarWrapper)
|
|
86
|
+
|
|
87
|
+
- **Styling**: Class name merging with Tailwind CSS3. [ServicesPopup](https://github.com/bikirandev/bikiran-utils/wiki/05.-ServicePopup)
|
|
88
|
+
|
|
89
|
+
- **State Management**: Cookie handling, local storage utilities4. [ButtonWrapper](https://github.com/bikirandev/bikiran-utils/wiki/04.-ButtonWrapper)
|
|
90
|
+
|
|
91
|
+
- **Type Safety**: TypeScript definitions and type guards5. [CurrencySelector](https://github.com/bikirandev/bikiran-utils/wiki/06.-CurrencySelector)
|
|
27
92
|
|
|
28
|
-
1. [Pagination](https://github.com/bikirandev/bikiran-utils/wiki/02.-Pagination)
|
|
29
|
-
2. [FilterBarWrapper](https://github.com/bikirandev/bikiran-utils/wiki/03.-FilterBarWrapper)
|
|
30
|
-
3. [ServicesPopup](https://github.com/bikirandev/bikiran-utils/wiki/05.-ServicePopup)
|
|
31
|
-
4. [ButtonWrapper](https://github.com/bikirandev/bikiran-utils/wiki/04.-ButtonWrapper)
|
|
32
|
-
5. [CurrencySelector](https://github.com/bikirandev/bikiran-utils/wiki/06.-CurrencySelector)
|
|
33
93
|
6. [CustomSidebar](https://github.com/bikirandev/bikiran-utils/wiki/07.-CustomSidebar)
|
|
34
|
-
|
|
94
|
+
|
|
95
|
+
## 🏗️ Dependencies7. [PageLoading](https://github.com/bikirandev/bikiran-utils/wiki/08.-PageLoading)
|
|
96
|
+
|
|
35
97
|
8. [LoadingComp](https://github.com/bikirandev/bikiran-utils/wiki/09.-LoadingComp)
|
|
36
|
-
9. [CookiesAcceptPopup](https://github.com/bikirandev/bikiran-utils/wiki/10.-CookiesAcceptPopup)
|
|
37
|
-
10. [ProfileManage](https://github.com/bikirandev/bikiran-utils/wiki/11.-ProfileManage)
|
|
38
|
-
11. [TooltipUserInfo](https://github.com/bikirandev/bikiran-utils/wiki/12.-TooltipUserInfo)
|
|
39
|
-
12. [UserInfoComp](https://github.com/bikirandev/bikiran-utils/wiki/13.-UserInfoComp)
|
|
40
98
|
|
|
41
|
-
|
|
99
|
+
### Core Dependencies9. [CookiesAcceptPopup](https://github.com/bikirandev/bikiran-utils/wiki/10.-CookiesAcceptPopup)
|
|
100
|
+
|
|
101
|
+
- `clsx` - Conditional class name utility10. [ProfileManage](https://github.com/bikirandev/bikiran-utils/wiki/11.-ProfileManage)
|
|
102
|
+
|
|
103
|
+
- `tailwind-merge` - Tailwind CSS class merging11. [TooltipUserInfo](https://github.com/bikirandev/bikiran-utils/wiki/12.-TooltipUserInfo)
|
|
104
|
+
|
|
105
|
+
- `Next.js` - React framework (recommended)12. [UserInfoComp](https://github.com/bikirandev/bikiran-utils/wiki/13.-UserInfoComp)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Peer Dependencies## Getting Started
|
|
110
|
+
|
|
42
111
|
|
|
43
|
-
### Installation
|
|
44
112
|
|
|
45
|
-
|
|
113
|
+
The following packages are required to be installed in your project:### Installation
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
- `react` (^19.1.0) - React libraryInstall the package via **npm**:
|
|
118
|
+
|
|
119
|
+
- `react-dom` (^19.1.0) - React DOM rendering
|
|
120
|
+
|
|
121
|
+
- `dayjs` (^1.11.0) - Date/time manipulation and formatting```bash
|
|
46
122
|
|
|
47
|
-
```bash
|
|
48
123
|
npm install @bikiran/utils
|
|
49
|
-
```
|
|
50
124
|
|
|
51
|
-
|
|
125
|
+
**Install peer dependencies:**```
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
```bashOr via **yarn**:
|
|
130
|
+
|
|
131
|
+
npm install react react-dom dayjs
|
|
132
|
+
|
|
133
|
+
``````bash
|
|
52
134
|
|
|
53
|
-
```bash
|
|
54
135
|
yarn add @bikiran/utils
|
|
55
|
-
```
|
|
56
136
|
|
|
57
|
-
|
|
137
|
+
## 🚀 Available Components```
|
|
58
138
|
|
|
59
|
-
### How It Works
|
|
60
139
|
|
|
61
|
-
This package is designed to **seamlessly inherit your project’s Tailwind CSS theme**. It automatically uses your existing:
|
|
62
140
|
|
|
63
|
-
|
|
64
|
-
- **Font families**
|
|
65
|
-
- **Spacing scale**
|
|
66
|
-
- **Other design tokens**
|
|
141
|
+
Each component below links to its own documentation page for detailed usage:---
|
|
67
142
|
|
|
68
|
-
No extra configuration is needed—just ensure your `tailwind.config.js` is properly set up.
|
|
69
143
|
|
|
70
|
-
|
|
144
|
+
|
|
145
|
+
### 📋 **Navigation & Layout**### How It Works
|
|
146
|
+
|
|
147
|
+
1. [CustomSidebar](https://github.com/bikirandev/bikiran-utils/wiki/07.-CustomSidebar) - Responsive sidebar with navigation
|
|
148
|
+
|
|
149
|
+
2. [ProjectSelector](https://github.com/bikirandev/bikiran-utils/wiki/ProjectSelector) - Project selection dropdownThis package is designed to **seamlessly inherit your project’s Tailwind CSS theme**. It automatically uses your existing:
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### 👤 **User & Profile** - **Primary/secondary colors**
|
|
154
|
+
|
|
155
|
+
3. [ProfileManage](https://github.com/bikirandev/bikiran-utils/wiki/11.-ProfileManage) - Complete profile management system- **Font families**
|
|
156
|
+
|
|
157
|
+
4. [UserInfoComp](https://github.com/bikirandev/bikiran-utils/wiki/13.-UserInfoComp) - User information display- **Spacing scale**
|
|
158
|
+
|
|
159
|
+
5. [TooltipUserInfo](https://github.com/bikirandev/bikiran-utils/wiki/12.-TooltipUserInfo) - User info in tooltip format- **Other design tokens**
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### 🎛️ **Interactive Controls**No extra configuration is needed—just ensure your `tailwind.config.js` is properly set up.
|
|
164
|
+
|
|
165
|
+
6. [ButtonWrapper](https://github.com/bikirandev/bikiran-utils/wiki/04.-ButtonWrapper) - Enhanced button component
|
|
166
|
+
|
|
167
|
+
7. [CurrencySelector](https://github.com/bikirandev/bikiran-utils/wiki/06.-CurrencySelector) - Currency selection dropdown#### Example:
|
|
168
|
+
|
|
169
|
+
8. [FilterBarWrapper](https://github.com/bikirandev/bikiran-utils/wiki/03.-FilterBarWrapper) - Advanced filtering interface
|
|
71
170
|
|
|
72
171
|
Your `tailwind.config.js` should define colors using CSS variables like this:
|
|
73
172
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
173
|
+
### 📄 **Data & Display**
|
|
174
|
+
|
|
175
|
+
9. [Pagination](https://github.com/bikirandev/bikiran-utils/wiki/02.-Pagination) - Pagination controls```js
|
|
176
|
+
|
|
177
|
+
10. [InformationTooltip](https://github.com/bikirandev/bikiran-utils/wiki/InformationTooltip) - Information tooltipstheme: {
|
|
178
|
+
|
|
179
|
+
11. [CopyWrapper](https://github.com/bikirandev/bikiran-utils/wiki/CopyWrapper) - Copy-to-clipboard functionality extend: {
|
|
180
|
+
|
|
77
181
|
colors: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
182
|
+
|
|
183
|
+
### ⏳ **Loading & Feedback** primary: {
|
|
184
|
+
|
|
185
|
+
12. [PageLoading](https://github.com/bikirandev/bikiran-utils/wiki/08.-PageLoading) - Full-page loading state DEFAULT: "var(--primary)",
|
|
186
|
+
|
|
187
|
+
13. [LoadingComp](https://github.com/bikirandev/bikiran-utils/wiki/09.-LoadingComp) - Inline loading component 50: "var(--primary-50)",
|
|
188
|
+
|
|
189
|
+
14. [CookiesAcceptPopup](https://github.com/bikirandev/bikiran-utils/wiki/10.-CookiesAcceptPopup) - GDPR cookie consent 100: "var(--primary-100)",
|
|
190
|
+
|
|
82
191
|
200: "var(--primary-200)",
|
|
83
|
-
|
|
84
|
-
|
|
192
|
+
|
|
193
|
+
### 🔗 **Integration & Services** 300: "var(--primary-300)",
|
|
194
|
+
|
|
195
|
+
15. [ServicesPopup](https://github.com/bikirandev/bikiran-utils/wiki/05.-ServicePopup) - Service app launcher 500: "var(--primary-500)",
|
|
196
|
+
|
|
85
197
|
700: "var(--primary-700)",
|
|
86
|
-
|
|
198
|
+
|
|
199
|
+
## 📚 Getting Started 900: "var(--primary-900)",
|
|
200
|
+
|
|
87
201
|
},
|
|
88
|
-
|
|
202
|
+
|
|
203
|
+
### Installation secondary: {
|
|
204
|
+
|
|
89
205
|
DEFAULT: "var(--secondary)",
|
|
90
|
-
|
|
206
|
+
|
|
207
|
+
Install the package via **npm**: 50: "var(--secondary-50)",
|
|
208
|
+
|
|
91
209
|
100: "var(--secondary-100)",
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
210
|
+
|
|
211
|
+
```bash 300: "var(--secondary-300)",
|
|
212
|
+
|
|
213
|
+
npm install @bikiran/utils 500: "var(--secondary-500)",
|
|
214
|
+
|
|
215
|
+
``` 700: "var(--secondary-700)",
|
|
216
|
+
|
|
95
217
|
900: "var(--secondary-900)",
|
|
96
|
-
|
|
218
|
+
|
|
219
|
+
Or via **yarn**: },
|
|
220
|
+
|
|
97
221
|
},
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
222
|
|
|
102
|
-
|
|
223
|
+
```bash },
|
|
103
224
|
|
|
104
|
-
|
|
225
|
+
yarn add @bikiran/utils}
|
|
105
226
|
|
|
106
|
-
|
|
227
|
+
``````
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
Or via **pnpm**:This setup allows all components—like `<ButtonWrapper>` and `<CurrencySelector>`—to **automatically inherit your color scheme** across different shades.
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
```bash### Basic Usage
|
|
236
|
+
|
|
237
|
+
pnpm add @bikiran/utils
|
|
238
|
+
|
|
239
|
+
```1. **Import Components**
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
--- ```tsx
|
|
107
244
|
|
|
108
|
-
```tsx
|
|
109
245
|
import { ButtonWrapper, PageLoading } from "7502NPM-Bikiran-Utils";
|
|
110
|
-
```
|
|
111
246
|
|
|
112
|
-
|
|
247
|
+
### 🎨 How It Works ```
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
This package is designed to **seamlessly inherit your project's Tailwind CSS theme**. It automatically uses your existing:2. **Use with Your Theme**
|
|
252
|
+
|
|
113
253
|
```tsx
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
254
|
+
|
|
255
|
+
- **Primary/secondary colors** // Buttons will adopt your project's `primary`/`secondary` colors
|
|
256
|
+
|
|
257
|
+
- **Font families** <ButtonWrapper variant="primary">Click Me</ButtonWrapper>
|
|
258
|
+
|
|
259
|
+
- **Spacing scale** ```
|
|
260
|
+
|
|
261
|
+
- **Other design tokens**
|
|
117
262
|
|
|
118
263
|
### Customization (Optional)
|
|
119
264
|
|
|
265
|
+
No extra configuration is needed—just ensure your `tailwind.config.js` is properly set up.
|
|
266
|
+
|
|
120
267
|
To override styles:
|
|
121
268
|
|
|
269
|
+
#### Example Configuration:
|
|
270
|
+
|
|
122
271
|
- Use `className` props (e.g., `<ButtonWrapper className="bg-red-500">`)
|
|
123
|
-
- Extend your Tailwind config (recommended for consistency)
|
|
124
272
|
|
|
125
|
-
|
|
273
|
+
Your `tailwind.config.js` should define colors using CSS variables like this:- Extend your Tailwind config (recommended for consistency)
|
|
126
274
|
|
|
127
|
-
- Next.js 14+
|
|
128
|
-
- Tailwind CSS v3+ (**must** have `primary`/`secondary` colors defined)
|
|
129
275
|
|
|
130
|
-
## Documentation
|
|
131
276
|
|
|
132
|
-
|
|
133
|
-
[Components Documentation](https://github.com/bikirandev/bikiran-utils/wiki/Home)
|
|
277
|
+
```js### Requirements
|
|
134
278
|
|
|
135
|
-
|
|
279
|
+
module.exports = {
|
|
136
280
|
|
|
137
|
-
|
|
281
|
+
theme: {- Next.js 14+
|
|
138
282
|
|
|
139
|
-
|
|
283
|
+
extend: {- Tailwind CSS v3+ (**must** have `primary`/`secondary` colors defined)
|
|
284
|
+
|
|
285
|
+
colors: {
|
|
286
|
+
|
|
287
|
+
primary: {## Documentation
|
|
288
|
+
|
|
289
|
+
DEFAULT: "var(--primary)",
|
|
290
|
+
|
|
291
|
+
50: "var(--primary-50)",For complete documentation and usage examples, please see:
|
|
292
|
+
|
|
293
|
+
100: "var(--primary-100)",[Components Documentation](https://github.com/bikirandev/bikiran-utils/wiki/Home)
|
|
294
|
+
|
|
295
|
+
200: "var(--primary-200)",
|
|
296
|
+
|
|
297
|
+
300: "var(--primary-300)",Sure! Here's just the **"How to Contribute"** section in Markdown:
|
|
298
|
+
|
|
299
|
+
500: "var(--primary-500)",
|
|
300
|
+
|
|
301
|
+
700: "var(--primary-700)",## 🤝 How to Contribute
|
|
302
|
+
|
|
303
|
+
900: "var(--primary-900)",
|
|
304
|
+
|
|
305
|
+
},We welcome contributions! To contribute to the package :
|
|
306
|
+
|
|
307
|
+
secondary: {
|
|
308
|
+
|
|
309
|
+
DEFAULT: "var(--secondary)",1. **Fork the repository** and clone your fork locally.
|
|
310
|
+
|
|
311
|
+
50: "var(--secondary-50)",2. **Create a new branch** for your feature or bugfix:
|
|
312
|
+
|
|
313
|
+
100: "var(--secondary-100)", ```
|
|
314
|
+
|
|
315
|
+
300: "var(--secondary-300)", git checkout -b my-feature-name
|
|
316
|
+
|
|
317
|
+
500: "var(--secondary-500)", ```
|
|
318
|
+
|
|
319
|
+
700: "var(--secondary-700)",3. Make your changes in supporting files.
|
|
320
|
+
|
|
321
|
+
900: "var(--secondary-900)",4. If you’re adding a feature or behavior, consider updating the docs or usage example.
|
|
322
|
+
|
|
323
|
+
},5. Commit your changes:
|
|
324
|
+
|
|
325
|
+
}, ```
|
|
326
|
+
|
|
327
|
+
}, git commit -m "feat: add awesome feature"
|
|
328
|
+
|
|
329
|
+
}, ```
|
|
330
|
+
|
|
331
|
+
plugins: [],6. Push to your fork:
|
|
332
|
+
|
|
333
|
+
} ```
|
|
334
|
+
|
|
335
|
+
``` git push origin my-feature-name
|
|
140
336
|
|
|
141
|
-
1. **Fork the repository** and clone your fork locally.
|
|
142
|
-
2. **Create a new branch** for your feature or bugfix:
|
|
143
337
|
```
|
|
144
|
-
|
|
338
|
+
|
|
339
|
+
This setup allows all components—like `<ButtonWrapper>` and `<CurrencySelector>`—to **automatically inherit your color scheme** across different shades.7. **Open a Pull Request** with a clear title and description.
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
### 🔧 Basic Usage### 🧪 Before submitting:
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
1. **Import Components**- Run and test the component in your app.
|
|
348
|
+
|
|
349
|
+
- Check for console errors or style breakages.
|
|
350
|
+
|
|
351
|
+
```tsx- Use consistent naming and follow the existing code style.
|
|
352
|
+
|
|
353
|
+
import {
|
|
354
|
+
|
|
355
|
+
ButtonWrapper, Thanks for your contribution! ❤️
|
|
356
|
+
|
|
357
|
+
PageLoading,
|
|
358
|
+
|
|
359
|
+
UserInfoComp,## License
|
|
360
|
+
|
|
361
|
+
CopyWrapper,
|
|
362
|
+
|
|
363
|
+
Pagination MIT License
|
|
364
|
+
|
|
365
|
+
} from "@bikiran/utils";
|
|
366
|
+
|
|
367
|
+
```## Author
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
2. **Import Utility Functions**Developed by [Bikiran](https://bikiran.com/)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
```tsx
|
|
376
|
+
import {
|
|
377
|
+
GetDate,
|
|
378
|
+
GetTime,
|
|
379
|
+
timeAgo,
|
|
380
|
+
capitalizeFirstLetter
|
|
381
|
+
} from "@bikiran/utils";
|
|
145
382
|
```
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
383
|
+
|
|
384
|
+
3. **Use with Your Theme**
|
|
385
|
+
```tsx
|
|
386
|
+
// Components automatically adopt your project's colors
|
|
387
|
+
<ButtonWrapper variant="primary">Click Me</ButtonWrapper>
|
|
388
|
+
|
|
389
|
+
// Utility functions work independently
|
|
390
|
+
const formattedDate = GetDate(Date.now() / 1000, "DD MMM YYYY");
|
|
149
391
|
```
|
|
150
|
-
|
|
392
|
+
|
|
393
|
+
### 🎛️ Customization (Optional)
|
|
394
|
+
|
|
395
|
+
To override default styles:
|
|
396
|
+
|
|
397
|
+
- **Use `className` props**: `<ButtonWrapper className="bg-red-500 hover:bg-red-600">`
|
|
398
|
+
- **Extend your Tailwind config**: Recommended for maintaining consistency
|
|
399
|
+
- **CSS custom properties**: Override CSS variables in your global styles
|
|
400
|
+
|
|
401
|
+
### 📋 Requirements
|
|
402
|
+
|
|
403
|
+
- **React** 19.1.0+
|
|
404
|
+
- **Next.js** 14+ (recommended)
|
|
405
|
+
- **Tailwind CSS** v3+ with `primary`/`secondary` colors defined
|
|
406
|
+
- **dayjs** 1.11.0+ for date utilities
|
|
407
|
+
|
|
408
|
+
## 🔧 Component Examples
|
|
409
|
+
|
|
410
|
+
### Quick Examples
|
|
411
|
+
|
|
412
|
+
```tsx
|
|
413
|
+
// Profile with user information
|
|
414
|
+
<UserInfoComp
|
|
415
|
+
name="John Doe"
|
|
416
|
+
email="john@example.com"
|
|
417
|
+
photoUrl="https://example.com/photo.jpg"
|
|
418
|
+
ImageComponent={Image}
|
|
419
|
+
/>
|
|
420
|
+
|
|
421
|
+
// Copy functionality
|
|
422
|
+
<CopyWrapper content="Copy this text">
|
|
423
|
+
Click to copy
|
|
424
|
+
</CopyWrapper>
|
|
425
|
+
|
|
426
|
+
// Loading states
|
|
427
|
+
{loading && <PageLoading />}
|
|
428
|
+
{processing && <LoadingComp />}
|
|
429
|
+
|
|
430
|
+
// Navigation
|
|
431
|
+
<Pagination
|
|
432
|
+
currentPage={1}
|
|
433
|
+
totalPages={10}
|
|
434
|
+
onPageChange={(page) => setCurrentPage(page)}
|
|
435
|
+
/>
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Advanced Usage
|
|
439
|
+
|
|
440
|
+
```tsx
|
|
441
|
+
// Complete profile management
|
|
442
|
+
<ProfileManage
|
|
443
|
+
LinkComponent={Link}
|
|
444
|
+
ImageComponent={Image}
|
|
445
|
+
AuthCompWrapper={AuthWrapper}
|
|
446
|
+
authFn={() => ({
|
|
447
|
+
authInfo: user,
|
|
448
|
+
logOut: handleLogout,
|
|
449
|
+
loginUrl: "/login"
|
|
450
|
+
})}
|
|
451
|
+
/>
|
|
452
|
+
|
|
453
|
+
// Service popup with apps
|
|
454
|
+
<ServicesPopup
|
|
455
|
+
staticAppLogo="/logo.png"
|
|
456
|
+
appsData={serviceApps}
|
|
457
|
+
LinkComponent={Link}
|
|
458
|
+
ImageComponent={Image}
|
|
459
|
+
/>
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## 🛠️ Utility Functions
|
|
463
|
+
|
|
464
|
+
### Date & Time Utilities
|
|
465
|
+
|
|
466
|
+
```tsx
|
|
467
|
+
import { GetDate, GetTime, timeAgo, timeRemaining } from "@bikiran/utils";
|
|
468
|
+
|
|
469
|
+
// Format dates
|
|
470
|
+
const formatted = GetDate(timestamp, "DD MMM YYYY"); // "07 Oct 2025"
|
|
471
|
+
const time = GetTime(timestamp, "HH:mm A"); // "02:30 PM"
|
|
472
|
+
|
|
473
|
+
// Relative time
|
|
474
|
+
const relative = timeAgo(timestamp); // "2 hours ago"
|
|
475
|
+
const remaining = timeRemaining(futureTimestamp); // "3 days remaining"
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Text & Data Utilities
|
|
479
|
+
|
|
480
|
+
```tsx
|
|
481
|
+
import { capitalizeFirstLetter, Copy } from "@bikiran/utils";
|
|
482
|
+
|
|
483
|
+
// Text processing
|
|
484
|
+
const capitalized = capitalizeFirstLetter("hello world"); // "Hello world"
|
|
485
|
+
|
|
486
|
+
// Copy functionality (React hook)
|
|
487
|
+
const MyCopyComponent = () => {
|
|
488
|
+
const { copy, isCopied } = Copy();
|
|
489
|
+
|
|
490
|
+
return (
|
|
491
|
+
<button onClick={() => copy("Text to copy")}>
|
|
492
|
+
{isCopied ? "Copied!" : "Copy Text"}
|
|
493
|
+
</button>
|
|
494
|
+
);
|
|
495
|
+
};
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### CSS & Styling
|
|
499
|
+
|
|
500
|
+
```tsx
|
|
501
|
+
import { cn } from "@bikiran/utils";
|
|
502
|
+
|
|
503
|
+
// Merge Tailwind classes efficiently
|
|
504
|
+
const buttonClasses = cn(
|
|
505
|
+
"px-4 py-2 rounded",
|
|
506
|
+
isActive && "bg-blue-500",
|
|
507
|
+
isDisabled && "opacity-50 cursor-not-allowed"
|
|
508
|
+
);
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## 📖 Documentation
|
|
512
|
+
|
|
513
|
+
For complete documentation and usage examples, please see:
|
|
514
|
+
[**📚 Components Documentation**](https://github.com/bikirandev/bikiran-utils/wiki/Home)
|
|
515
|
+
|
|
516
|
+
### 🔗 Quick Links
|
|
517
|
+
- [Installation Guide](https://github.com/bikirandev/bikiran-utils/wiki/Installation)
|
|
518
|
+
- [Component API Reference](https://github.com/bikirandev/bikiran-utils/wiki/Components)
|
|
519
|
+
- [Utility Functions](https://github.com/bikirandev/bikiran-utils/wiki/Utilities)
|
|
520
|
+
- [Examples & Demos](https://github.com/bikirandev/bikiran-utils/wiki/Examples)
|
|
521
|
+
|
|
522
|
+
## 🤝 How to Contribute
|
|
523
|
+
|
|
524
|
+
We welcome contributions! To contribute to the package:
|
|
525
|
+
|
|
526
|
+
1. **Fork the repository** and clone your fork locally
|
|
527
|
+
2. **Create a new branch** for your feature or bugfix:
|
|
528
|
+
```bash
|
|
529
|
+
git checkout -b feature/my-awesome-feature
|
|
151
530
|
```
|
|
152
|
-
|
|
531
|
+
3. **Make your changes** in supporting files
|
|
532
|
+
4. **Add tests** and update documentation if needed
|
|
533
|
+
5. **Test your changes** thoroughly
|
|
534
|
+
6. **Commit your changes** with descriptive messages:
|
|
535
|
+
```bash
|
|
536
|
+
git commit -m "feat: add awesome new feature"
|
|
153
537
|
```
|
|
154
|
-
|
|
538
|
+
7. **Push to your fork** and create a Pull Request:
|
|
539
|
+
```bash
|
|
540
|
+
git push origin feature/my-awesome-feature
|
|
155
541
|
```
|
|
156
|
-
7. **Open a Pull Request** with a clear title and description.
|
|
157
542
|
|
|
158
|
-
### 🧪 Before
|
|
543
|
+
### 🧪 Before Submitting
|
|
159
544
|
|
|
160
|
-
- Run and
|
|
161
|
-
-
|
|
162
|
-
-
|
|
545
|
+
- ✅ Run tests and ensure all pass
|
|
546
|
+
- ✅ Test components in a real application
|
|
547
|
+
- ✅ Check for console errors or style conflicts
|
|
548
|
+
- ✅ Follow existing code style and naming conventions
|
|
549
|
+
- ✅ Update documentation for new features
|
|
550
|
+
- ✅ Add TypeScript definitions for new exports
|
|
551
|
+
|
|
552
|
+
### 📝 Contribution Guidelines
|
|
553
|
+
|
|
554
|
+
- **Bug Reports**: Use GitHub Issues with detailed reproduction steps
|
|
555
|
+
- **Feature Requests**: Discuss in Issues before implementing
|
|
556
|
+
- **Code Style**: Follow existing patterns and use TypeScript
|
|
557
|
+
- **Testing**: Add tests for new functionality
|
|
558
|
+
- **Documentation**: Update README and wiki documentation
|
|
163
559
|
|
|
164
560
|
Thanks for your contribution! ❤️
|
|
165
561
|
|
|
166
|
-
## License
|
|
562
|
+
## 📄 License
|
|
563
|
+
|
|
564
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
565
|
+
|
|
566
|
+
## 👨💻 Author
|
|
567
|
+
|
|
568
|
+
**Developed by [Kumar Bishojit Paul](https://bikiran.com/)**
|
|
569
|
+
|
|
570
|
+
- 🌐 Website: [bikiran.com](https://bikiran.com/)
|
|
571
|
+
- 📧 Email: [Contact](https://bikiran.com/contact)
|
|
572
|
+
- 🐙 GitHub: [@bikirandev](https://github.com/bikirandev)
|
|
573
|
+
|
|
574
|
+
---
|
|
167
575
|
|
|
168
|
-
|
|
576
|
+
<div align="center">
|
|
169
577
|
|
|
170
|
-
|
|
578
|
+
**Made with ❤️ for the React community**
|
|
171
579
|
|
|
172
|
-
|
|
580
|
+
[⭐ Star this repo](https://github.com/bikirandev/bikiran-utils) • [🐛 Report Bug](https://github.com/bikirandev/bikiran-utils/issues) • [💡 Request Feature](https://github.com/bikirandev/bikiran-utils/issues/new)
|
|
173
581
|
|
|
582
|
+
</div>
|
package/dist/index.d.ts
CHANGED
|
@@ -13,3 +13,14 @@ export { default as UserInfoComp } from "./components/user-info/UserInfoComp";
|
|
|
13
13
|
export { default as ProjectSelector } from "./components/project-selector/ProjectSelector";
|
|
14
14
|
export { default as InformationTooltip } from "./components/information-tooltip/InformationTooltip";
|
|
15
15
|
export { default as CopyWrapper } from "./components/copy-wrapper/CopyWrapper";
|
|
16
|
+
export { GetDate, GetTime, timeAgo, timeRemaining } from "./lib/utils/date";
|
|
17
|
+
export { default as capitalizeFirstLetter } from "./lib/utils/capitalizeFirstLetter";
|
|
18
|
+
export { cn } from "./lib/utils/cn";
|
|
19
|
+
export { default as Copy } from "./lib/utils/Copy";
|
|
20
|
+
export { default as Cookie } from "./lib/utils/Cookie";
|
|
21
|
+
export { evaluate } from "./lib/utils/math";
|
|
22
|
+
export { md5 } from "./lib/utils/hash";
|
|
23
|
+
export { convertToYears } from "./lib/utils/convertToYears";
|
|
24
|
+
export { showCurrencySign, showInt } from "./lib/utils/show";
|
|
25
|
+
export { addOption, addOption2 } from "./lib/utils/option";
|
|
26
|
+
export { getBikiranUrl, getAccountUrl, getApiUrl, getApi2Url, getApi3Url, getBaseDomain, isDev, getMode, } from "./lib/utils/Env";
|
package/dist/index.js
CHANGED
|
@@ -13,3 +13,14 @@ export { default as UserInfoComp } from "./components/user-info/UserInfoComp";
|
|
|
13
13
|
export { default as ProjectSelector } from "./components/project-selector/ProjectSelector";
|
|
14
14
|
export { default as InformationTooltip } from "./components/information-tooltip/InformationTooltip";
|
|
15
15
|
export { default as CopyWrapper } from "./components/copy-wrapper/CopyWrapper";
|
|
16
|
+
export { GetDate, GetTime, timeAgo, timeRemaining } from "./lib/utils/date";
|
|
17
|
+
export { default as capitalizeFirstLetter } from "./lib/utils/capitalizeFirstLetter";
|
|
18
|
+
export { cn } from "./lib/utils/cn";
|
|
19
|
+
export { default as Copy } from "./lib/utils/Copy";
|
|
20
|
+
export { default as Cookie } from "./lib/utils/Cookie";
|
|
21
|
+
export { evaluate } from "./lib/utils/math";
|
|
22
|
+
export { md5 } from "./lib/utils/hash";
|
|
23
|
+
export { convertToYears } from "./lib/utils/convertToYears";
|
|
24
|
+
export { showCurrencySign, showInt } from "./lib/utils/show";
|
|
25
|
+
export { addOption, addOption2 } from "./lib/utils/option";
|
|
26
|
+
export { getBikiranUrl, getAccountUrl, getApiUrl, getApi2Url, getApi3Url, getBaseDomain, isDev, getMode, } from "./lib/utils/Env";
|
package/dist/index.ts
CHANGED
|
@@ -13,3 +13,23 @@ export { default as UserInfoComp } from "./components/user-info/UserInfoComp";
|
|
|
13
13
|
export { default as ProjectSelector } from "./components/project-selector/ProjectSelector";
|
|
14
14
|
export { default as InformationTooltip } from "./components/information-tooltip/InformationTooltip";
|
|
15
15
|
export { default as CopyWrapper } from "./components/copy-wrapper/CopyWrapper";
|
|
16
|
+
export { GetDate, GetTime, timeAgo, timeRemaining } from "./lib/utils/date";
|
|
17
|
+
export { default as capitalizeFirstLetter } from "./lib/utils/capitalizeFirstLetter";
|
|
18
|
+
export { cn } from "./lib/utils/cn";
|
|
19
|
+
export { default as Copy } from "./lib/utils/Copy";
|
|
20
|
+
export { default as Cookie } from "./lib/utils/Cookie";
|
|
21
|
+
export { evaluate } from "./lib/utils/math";
|
|
22
|
+
export { md5 } from "./lib/utils/hash";
|
|
23
|
+
export { convertToYears } from "./lib/utils/convertToYears";
|
|
24
|
+
export { showCurrencySign, showInt } from "./lib/utils/show";
|
|
25
|
+
export { addOption, addOption2 } from "./lib/utils/option";
|
|
26
|
+
export {
|
|
27
|
+
getBikiranUrl,
|
|
28
|
+
getAccountUrl,
|
|
29
|
+
getApiUrl,
|
|
30
|
+
getApi2Url,
|
|
31
|
+
getApi3Url,
|
|
32
|
+
getBaseDomain,
|
|
33
|
+
isDev,
|
|
34
|
+
getMode,
|
|
35
|
+
} from "./lib/utils/Env";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function convertToYears(quantity: number, unit?: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function convertToYears(quantity, unit) {
|
|
2
|
+
// Default to "months" if no unit provided
|
|
3
|
+
const normalizedUnit = (unit === null || unit === void 0 ? void 0 : unit.toLowerCase()) || "months";
|
|
4
|
+
// Calculate years based on unit
|
|
5
|
+
let years;
|
|
6
|
+
switch (normalizedUnit) {
|
|
7
|
+
case "day":
|
|
8
|
+
case "days":
|
|
9
|
+
years = quantity / 365;
|
|
10
|
+
// If less than a year, return the original quantity with unit
|
|
11
|
+
if (years < 1)
|
|
12
|
+
return `${quantity} D`;
|
|
13
|
+
break;
|
|
14
|
+
case "week":
|
|
15
|
+
case "weeks":
|
|
16
|
+
years = quantity / 52;
|
|
17
|
+
// If less than a year, return the original quantity with unit
|
|
18
|
+
if (years < 1)
|
|
19
|
+
return `${quantity} W`;
|
|
20
|
+
break;
|
|
21
|
+
case "month":
|
|
22
|
+
case "months":
|
|
23
|
+
years = quantity / 12;
|
|
24
|
+
// If less than a year, return the original quantity with unit
|
|
25
|
+
if (years < 1)
|
|
26
|
+
return `${quantity} M`;
|
|
27
|
+
break;
|
|
28
|
+
case "year":
|
|
29
|
+
case "years":
|
|
30
|
+
years = quantity;
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
years = quantity / 12; // Default to months if unknown unit
|
|
34
|
+
// If less than a year, return the original quantity with unit
|
|
35
|
+
if (years < 1)
|
|
36
|
+
return `${quantity} M`;
|
|
37
|
+
}
|
|
38
|
+
// Format the result with up to 2 decimal places, removing trailing zeros
|
|
39
|
+
const formattedYears = years % 1 === 0 ? years.toString() : years.toFixed(2).replace(/\.?0+$/, "");
|
|
40
|
+
// Return the formatted result
|
|
41
|
+
return `${formattedYears}y`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function convertToYears(quantity: number, unit?: string): string {
|
|
2
|
+
// Default to "months" if no unit provided
|
|
3
|
+
const normalizedUnit = unit?.toLowerCase() || "months";
|
|
4
|
+
|
|
5
|
+
// Calculate years based on unit
|
|
6
|
+
let years: number;
|
|
7
|
+
switch (normalizedUnit) {
|
|
8
|
+
case "day":
|
|
9
|
+
case "days":
|
|
10
|
+
years = quantity / 365;
|
|
11
|
+
// If less than a year, return the original quantity with unit
|
|
12
|
+
if (years < 1) return `${quantity} D`;
|
|
13
|
+
break;
|
|
14
|
+
case "week":
|
|
15
|
+
case "weeks":
|
|
16
|
+
years = quantity / 52;
|
|
17
|
+
// If less than a year, return the original quantity with unit
|
|
18
|
+
if (years < 1) return `${quantity} W`;
|
|
19
|
+
break;
|
|
20
|
+
case "month":
|
|
21
|
+
case "months":
|
|
22
|
+
years = quantity / 12;
|
|
23
|
+
// If less than a year, return the original quantity with unit
|
|
24
|
+
if (years < 1) return `${quantity} M`;
|
|
25
|
+
break;
|
|
26
|
+
case "year":
|
|
27
|
+
case "years":
|
|
28
|
+
years = quantity;
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
years = quantity / 12; // Default to months if unknown unit
|
|
32
|
+
// If less than a year, return the original quantity with unit
|
|
33
|
+
if (years < 1) return `${quantity} M`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Format the result with up to 2 decimal places, removing trailing zeros
|
|
37
|
+
const formattedYears =
|
|
38
|
+
years % 1 === 0 ? years.toString() : years.toFixed(2).replace(/\.?0+$/, "");
|
|
39
|
+
|
|
40
|
+
// Return the formatted result
|
|
41
|
+
return `${formattedYears}y`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function GetDate(timeStamp: number | null | undefined, format?: string): string | null;
|
|
2
|
+
export declare function GetTime(timeStamp: number | null | undefined, format?: string): string | null;
|
|
3
|
+
export declare const timeAgo: (timestamp: number) => string;
|
|
4
|
+
export declare const timeRemaining: (timestamp: number) => string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
export function GetDate(timeStamp, format) {
|
|
3
|
+
if (!timeStamp) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const dateFormat = dayjs(timeStamp * 1000).format(format || `DD ${`MMMM`.slice(0, 3)} YYYY`);
|
|
7
|
+
return dateFormat.toString() !== "Invalid Date" ? dateFormat : "--";
|
|
8
|
+
}
|
|
9
|
+
export function GetTime(timeStamp, format = "h:mm:ss A") {
|
|
10
|
+
if (!timeStamp) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const dateFormat = dayjs(timeStamp * 1000).format(format);
|
|
14
|
+
return dateFormat.toString() || null;
|
|
15
|
+
}
|
|
16
|
+
export const timeAgo = (timestamp) => {
|
|
17
|
+
const now = new Date();
|
|
18
|
+
const date = new Date(timestamp * 1000); // Convert seconds to milliseconds
|
|
19
|
+
const seconds = Math.floor((now - date) / 1000);
|
|
20
|
+
let interval = Math.floor(seconds / 31536000); // 1 year in seconds
|
|
21
|
+
if (interval > 1)
|
|
22
|
+
return `${interval} years ago`;
|
|
23
|
+
interval = Math.floor(seconds / 2592000); // 1 month in seconds
|
|
24
|
+
if (interval > 1)
|
|
25
|
+
return `${interval} months ago`;
|
|
26
|
+
interval = Math.floor(seconds / 86400); // 1 day in seconds
|
|
27
|
+
if (interval > 1)
|
|
28
|
+
return `${interval} days ago`;
|
|
29
|
+
interval = Math.floor(seconds / 3600); // 1 hour in seconds
|
|
30
|
+
if (interval > 1)
|
|
31
|
+
return `${interval} hours ago`;
|
|
32
|
+
interval = Math.floor(seconds / 60); // 1 minute in seconds
|
|
33
|
+
if (interval > 1)
|
|
34
|
+
return `${interval} minutes ago`;
|
|
35
|
+
return `${seconds} seconds ago`;
|
|
36
|
+
};
|
|
37
|
+
export const timeRemaining = (timestamp) => {
|
|
38
|
+
const now = new Date();
|
|
39
|
+
const date = new Date(timestamp * 1000); // Convert seconds to milliseconds
|
|
40
|
+
const seconds = Math.floor((date.getTime() - now.getTime()) / 1000); // Remaining seconds
|
|
41
|
+
if (seconds < 0) {
|
|
42
|
+
return "Time has already passed"; // Handle past timestamp
|
|
43
|
+
}
|
|
44
|
+
let interval = Math.floor(seconds / 31536000); // 1 year in seconds
|
|
45
|
+
if (interval > 1)
|
|
46
|
+
return `${interval} years remaining`;
|
|
47
|
+
interval = Math.floor(seconds / 2592000); // 1 month in seconds
|
|
48
|
+
if (interval > 1)
|
|
49
|
+
return `${interval} months remaining`;
|
|
50
|
+
interval = Math.floor(seconds / 86400); // 1 day in seconds
|
|
51
|
+
if (interval > 1)
|
|
52
|
+
return `${interval} days remaining`;
|
|
53
|
+
interval = Math.floor(seconds / 3600); // 1 hour in seconds
|
|
54
|
+
if (interval > 1)
|
|
55
|
+
return `${interval} hours remaining`;
|
|
56
|
+
interval = Math.floor(seconds / 60); // 1 minute in seconds
|
|
57
|
+
if (interval > 1)
|
|
58
|
+
return `${interval} minutes remaining`;
|
|
59
|
+
return `${seconds} seconds remaining`;
|
|
60
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
|
|
3
|
+
export function GetDate(
|
|
4
|
+
timeStamp: number | null | undefined,
|
|
5
|
+
format?: string
|
|
6
|
+
): string | null {
|
|
7
|
+
if (!timeStamp) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const dateFormat = dayjs(timeStamp * 1000).format(
|
|
11
|
+
format || `DD ${`MMMM`.slice(0, 3)} YYYY`
|
|
12
|
+
);
|
|
13
|
+
return dateFormat.toString() !== "Invalid Date" ? dateFormat : "--";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function GetTime(
|
|
17
|
+
timeStamp: number | null | undefined,
|
|
18
|
+
format: string = "h:mm:ss A"
|
|
19
|
+
): string | null {
|
|
20
|
+
if (!timeStamp) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const dateFormat = dayjs(timeStamp * 1000).format(format);
|
|
24
|
+
return dateFormat.toString() || null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const timeAgo = (timestamp: number) => {
|
|
28
|
+
const now: any = new Date();
|
|
29
|
+
const date: any = new Date(timestamp * 1000); // Convert seconds to milliseconds
|
|
30
|
+
const seconds = Math.floor((now - date) / 1000);
|
|
31
|
+
|
|
32
|
+
let interval = Math.floor(seconds / 31536000); // 1 year in seconds
|
|
33
|
+
|
|
34
|
+
if (interval > 1) return `${interval} years ago`;
|
|
35
|
+
interval = Math.floor(seconds / 2592000); // 1 month in seconds
|
|
36
|
+
if (interval > 1) return `${interval} months ago`;
|
|
37
|
+
interval = Math.floor(seconds / 86400); // 1 day in seconds
|
|
38
|
+
if (interval > 1) return `${interval} days ago`;
|
|
39
|
+
interval = Math.floor(seconds / 3600); // 1 hour in seconds
|
|
40
|
+
if (interval > 1) return `${interval} hours ago`;
|
|
41
|
+
interval = Math.floor(seconds / 60); // 1 minute in seconds
|
|
42
|
+
if (interval > 1) return `${interval} minutes ago`;
|
|
43
|
+
return `${seconds} seconds ago`;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const timeRemaining = (timestamp: number) => {
|
|
47
|
+
const now: Date = new Date();
|
|
48
|
+
const date: Date = new Date(timestamp * 1000); // Convert seconds to milliseconds
|
|
49
|
+
const seconds = Math.floor((date.getTime() - now.getTime()) / 1000); // Remaining seconds
|
|
50
|
+
|
|
51
|
+
if (seconds < 0) {
|
|
52
|
+
return "Time has already passed"; // Handle past timestamp
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let interval = Math.floor(seconds / 31536000); // 1 year in seconds
|
|
56
|
+
|
|
57
|
+
if (interval > 1) return `${interval} years remaining`;
|
|
58
|
+
interval = Math.floor(seconds / 2592000); // 1 month in seconds
|
|
59
|
+
if (interval > 1) return `${interval} months remaining`;
|
|
60
|
+
interval = Math.floor(seconds / 86400); // 1 day in seconds
|
|
61
|
+
if (interval > 1) return `${interval} days remaining`;
|
|
62
|
+
interval = Math.floor(seconds / 3600); // 1 hour in seconds
|
|
63
|
+
if (interval > 1) return `${interval} hours remaining`;
|
|
64
|
+
interval = Math.floor(seconds / 60); // 1 minute in seconds
|
|
65
|
+
if (interval > 1) return `${interval} minutes remaining`;
|
|
66
|
+
|
|
67
|
+
return `${seconds} seconds remaining`;
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const md5: (input: string) => string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-eval */
|
|
2
|
+
export const evaluate = (val) => {
|
|
3
|
+
let output = val;
|
|
4
|
+
const isValOperatorOrNumber = /^[\d.*/+=-]*$/.test(val);
|
|
5
|
+
if (output.substring(output.length - 1, output.length) === "=") {
|
|
6
|
+
if (isValOperatorOrNumber) {
|
|
7
|
+
try {
|
|
8
|
+
output = eval(output.substring(0, output.length - 1));
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
output = 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
output = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return output;
|
|
19
|
+
};
|
|
20
|
+
export const round = (value, decimals = 4) => {
|
|
21
|
+
return Number(Math.round(Number(value + "e" + decimals)) + "e-" + decimals);
|
|
22
|
+
};
|
|
23
|
+
export default null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable no-eval */
|
|
2
|
+
|
|
3
|
+
export const evaluate = (val: any) => {
|
|
4
|
+
let output = val;
|
|
5
|
+
|
|
6
|
+
const isValOperatorOrNumber = /^[\d.*/+=-]*$/.test(val);
|
|
7
|
+
|
|
8
|
+
if (output.substring(output.length - 1, output.length) === "=") {
|
|
9
|
+
if (isValOperatorOrNumber) {
|
|
10
|
+
try {
|
|
11
|
+
output = eval(output.substring(0, output.length - 1));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
output = 0;
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
output = 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return output;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const round = (value: number, decimals: number = 4) => {
|
|
23
|
+
return Number(Math.round(Number(value + "e" + decimals)) + "e-" + decimals);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Cookie from "./Cookie";
|
|
2
|
+
import { getBaseDomain } from "./Env";
|
|
3
|
+
export const showCurrencySign = (currency) => {
|
|
4
|
+
const localeData = typeof window !== "undefined" ? new Cookie("locale", getBaseDomain()).getCookie() : null;
|
|
5
|
+
const value = currency === null || currency === void 0 ? void 0 : currency.toLowerCase();
|
|
6
|
+
const localeCurrency = localeData ? JSON.parse(localeData).currency : "";
|
|
7
|
+
if (currency !== undefined && (currency === null || currency === void 0 ? void 0 : currency.length) > 0) {
|
|
8
|
+
return value === "usd" ? "$" : value === "bdt" ? "৳" : "₹";
|
|
9
|
+
}
|
|
10
|
+
return (localeCurrency === null || localeCurrency === void 0 ? void 0 : localeCurrency.toLowerCase()) === "usd" ? "$" : (localeCurrency === null || localeCurrency === void 0 ? void 0 : localeCurrency.toLowerCase()) === "bdt" ? "৳" : "₹";
|
|
11
|
+
};
|
|
12
|
+
export const showInt = (value, fixedCount = 2) => {
|
|
13
|
+
var _a;
|
|
14
|
+
// Handle string input if needed
|
|
15
|
+
if (typeof value === "string") {
|
|
16
|
+
value = parseFloat(value || "0");
|
|
17
|
+
}
|
|
18
|
+
let formattedInt = (_a = value === null || value === void 0 ? void 0 : value.toFixed(fixedCount)) !== null && _a !== void 0 ? _a : "0.00";
|
|
19
|
+
const [integerPart, decimalPart] = formattedInt === null || formattedInt === void 0 ? void 0 : formattedInt.split(".");
|
|
20
|
+
const formattedInteger = formatNumber(integerPart);
|
|
21
|
+
formattedInt = decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger;
|
|
22
|
+
return formattedInt;
|
|
23
|
+
};
|
|
24
|
+
function formatNumber(numStr) {
|
|
25
|
+
const num = parseFloat(numStr);
|
|
26
|
+
if (isNaN(num))
|
|
27
|
+
return numStr; // handle invalid numbers
|
|
28
|
+
// Use international formatting (3-digit grouping)
|
|
29
|
+
return new Intl.NumberFormat("en-US").format(num);
|
|
30
|
+
// Or alternatively, without Intl.NumberFormat:
|
|
31
|
+
// const parts = numStr.split('.');
|
|
32
|
+
// parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
33
|
+
// return parts.join('.');
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Cookie from "./Cookie";
|
|
2
|
+
import { getBaseDomain } from "./Env";
|
|
3
|
+
|
|
4
|
+
export const showCurrencySign = (currency?: string) => {
|
|
5
|
+
const localeData = typeof window !== "undefined" ? new Cookie("locale", getBaseDomain()).getCookie() : null;
|
|
6
|
+
const value = currency?.toLowerCase();
|
|
7
|
+
const localeCurrency = localeData ? JSON.parse(localeData).currency : "";
|
|
8
|
+
|
|
9
|
+
if (currency !== undefined && currency?.length > 0) {
|
|
10
|
+
return value === "usd" ? "$" : value === "bdt" ? "৳" : "₹";
|
|
11
|
+
}
|
|
12
|
+
return localeCurrency?.toLowerCase() === "usd" ? "$" : localeCurrency?.toLowerCase() === "bdt" ? "৳" : "₹";
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const showInt = (value: number, fixedCount: number = 2) => {
|
|
16
|
+
// Handle string input if needed
|
|
17
|
+
if (typeof value === "string") {
|
|
18
|
+
value = parseFloat(value || "0");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let formattedInt = value?.toFixed(fixedCount) ?? "0.00";
|
|
22
|
+
const [integerPart, decimalPart] = formattedInt?.split(".");
|
|
23
|
+
const formattedInteger = formatNumber(integerPart);
|
|
24
|
+
formattedInt = decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger;
|
|
25
|
+
|
|
26
|
+
return formattedInt;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function formatNumber(numStr: string): string {
|
|
30
|
+
const num = parseFloat(numStr);
|
|
31
|
+
if (isNaN(num)) return numStr; // handle invalid numbers
|
|
32
|
+
|
|
33
|
+
// Use international formatting (3-digit grouping)
|
|
34
|
+
return new Intl.NumberFormat("en-US").format(num);
|
|
35
|
+
|
|
36
|
+
// Or alternatively, without Intl.NumberFormat:
|
|
37
|
+
// const parts = numStr.split('.');
|
|
38
|
+
// parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
39
|
+
// return parts.join('.');
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bikiran/utils",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": "^19.1.0",
|
|
44
|
-
"react-dom": "^19.1.0"
|
|
44
|
+
"react-dom": "^19.1.0",
|
|
45
|
+
"dayjs": "^1.11.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@testing-library/react": "^16.3.0",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"@types/react-dom": "^19.1.2",
|
|
51
52
|
"@vitejs/plugin-react": "^4.4.1",
|
|
52
53
|
"copyfiles": "^2.4.1",
|
|
54
|
+
"dayjs": "^1.11.13",
|
|
53
55
|
"jsdom": "^26.1.0",
|
|
54
56
|
"react": "^19.1.0",
|
|
55
57
|
"react-dom": "^19.1.0",
|