@pistachiojs/core 0.2.0-dev.0 → 0.2.0-dev.2
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 +80 -0
- package/dist/index.d.ts +114 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +21 -2
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @pistachiojs/core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic TypeScript utility library with pure functions for common programming tasks. Provides clean, functional utilities that work in any JavaScript environment with zero dependencies.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@pistachiojs/core)
|
|
6
|
+
[](../../coverage)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
## Key features
|
|
10
|
+
|
|
11
|
+
- **Full type safety** - TypeScript-first with complete inference
|
|
12
|
+
- **Framework agnostic** - Compatible with any JavaScript framework or library
|
|
13
|
+
- **Zero dependencies** - No external dependencies
|
|
14
|
+
- **Tree shakeable** - Modular imports for minimal bundle size
|
|
15
|
+
- **Well tested** - Comprehensive test coverage
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# npm
|
|
21
|
+
npm install @pistachiojs/core
|
|
22
|
+
|
|
23
|
+
# pnpm
|
|
24
|
+
pnpm add @pistachiojs/core
|
|
25
|
+
|
|
26
|
+
# yarn
|
|
27
|
+
yarn add @pistachiojs/core
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### ESM (ES Modules)
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import { isArray, toCamelCase } from '@pistachiojs/core'
|
|
36
|
+
|
|
37
|
+
// Type checking
|
|
38
|
+
isArray([1, 2, 3]) // true
|
|
39
|
+
isArray('hello') // false
|
|
40
|
+
|
|
41
|
+
// String transformation
|
|
42
|
+
toCamelCase('hello-world') // 'helloWorld'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### CommonJS
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
const { isArray, toCamelCase } = require('@pistachiojs/core')
|
|
49
|
+
|
|
50
|
+
// Type checking
|
|
51
|
+
isArray([1, 2, 3]) // true
|
|
52
|
+
isArray('hello') // false
|
|
53
|
+
|
|
54
|
+
// String transformation
|
|
55
|
+
toCamelCase('hello-world') // 'helloWorld'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Type safety
|
|
59
|
+
|
|
60
|
+
This package is written in TypeScript and includes type definitions out of the box.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { map, isString } from '@pistachiojs/core'
|
|
64
|
+
|
|
65
|
+
// Full type inference
|
|
66
|
+
const numbers: number[] = [1, 2, 3]
|
|
67
|
+
const doubled = map(numbers, (n) => n * 2) // number[]
|
|
68
|
+
|
|
69
|
+
// Type guards narrow types
|
|
70
|
+
function process(value: unknown) {
|
|
71
|
+
if (isString(value)) {
|
|
72
|
+
// value is now typed as string
|
|
73
|
+
return value.toUpperCase()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT © [Dirga Prakesha](https://github.com/dirgaprksha)
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,119 @@ declare function map<T, U>(value: readonly T[], callbackFn: (item: T, index: num
|
|
|
49
49
|
*/
|
|
50
50
|
declare function sort<T>(value: readonly T[], compareFn?: (valueA: T, valueB: T) => number): T[];
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a value is an array.
|
|
54
|
+
* @param value - Value to check.
|
|
55
|
+
* @returns True if value is an array, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
declare function isArray(value: unknown): value is unknown[];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a value is a bigint.
|
|
61
|
+
* @param value - Value to check.
|
|
62
|
+
* @returns True if value is a bigint, false otherwise.
|
|
63
|
+
*/
|
|
64
|
+
declare function isBigInt(value: unknown): value is bigint;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a value is a boolean.
|
|
68
|
+
* @param value - Value to check.
|
|
69
|
+
* @returns True if value is a boolean, false otherwise.
|
|
70
|
+
*/
|
|
71
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a value is a date object.
|
|
75
|
+
* @param value - Value to check.
|
|
76
|
+
* @returns True if value is a date object, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
declare function isDate(value: unknown): value is Date;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Checks if a value is defined (not null or undefined).
|
|
82
|
+
* @param value - Value to check.
|
|
83
|
+
* @returns True if value is defined, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Checks if a value is empty (null, undefined, empty string, empty array or empty object).
|
|
89
|
+
* @param value - Value to check.
|
|
90
|
+
* @returns True if value is empty, false otherwise.
|
|
91
|
+
*/
|
|
92
|
+
declare function isEmpty(value: unknown): boolean;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Checks if an object is frozen.
|
|
96
|
+
* @param value - Value to check.
|
|
97
|
+
* @returns True if value is a frozen object, false otherwise.
|
|
98
|
+
*/
|
|
99
|
+
declare function isFreeze(value: unknown): boolean;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Checks if a value is a function.
|
|
103
|
+
* @param value - Value to check.
|
|
104
|
+
* @returns True if value is a function, false otherwise.
|
|
105
|
+
*/
|
|
106
|
+
declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Checks if a value is a number (excluding NaN).
|
|
110
|
+
* @param value - Value to check.
|
|
111
|
+
* @returns True if value is a number, false otherwise.
|
|
112
|
+
*/
|
|
113
|
+
declare function isNumber(value: unknown): value is number;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a value is an object (excluding arrays and null).
|
|
117
|
+
* @param value - Value to check.
|
|
118
|
+
* @returns True if value is an object, false otherwise.
|
|
119
|
+
*/
|
|
120
|
+
declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Checks if a value is a string.
|
|
124
|
+
* @param value - Value to check.
|
|
125
|
+
* @returns True if value is a string, false otherwise.
|
|
126
|
+
*/
|
|
127
|
+
declare function isString(value: unknown): value is string;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks if a value is a symbol.
|
|
131
|
+
* @param value - Value to check.
|
|
132
|
+
* @returns True if value is a symbol, false otherwise.
|
|
133
|
+
*/
|
|
134
|
+
declare function isSymbol(value: unknown): value is symbol;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a value is truthy.
|
|
138
|
+
* @param value - Value to check.
|
|
139
|
+
* @returns True if value is truthy, false otherwise.
|
|
140
|
+
*/
|
|
141
|
+
declare function isTruthy<T>(value: T): value is NonNullable<T>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Checks if a value is undefined.
|
|
145
|
+
* @param value - Value to check.
|
|
146
|
+
* @returns True if value is undefined, false otherwise.
|
|
147
|
+
*/
|
|
148
|
+
declare function isUndefined(value: unknown): value is undefined;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Freezes an object making it immutable.
|
|
152
|
+
* @param value - Object value to freeze.
|
|
153
|
+
* @returns Object value frozened.
|
|
154
|
+
*/
|
|
155
|
+
declare function freeze<T extends object>(value: T): Readonly<T>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Merges two objects into a new object.
|
|
159
|
+
* @param valueA - Object value to merge.
|
|
160
|
+
* @param valueB - Object value to merge.
|
|
161
|
+
* @returns New object value with properties from both objects.
|
|
162
|
+
*/
|
|
163
|
+
declare function merge<T extends object, U extends object>(valueA: T, valueB: U): T & U;
|
|
164
|
+
|
|
52
165
|
/**
|
|
53
166
|
* Extracts a section of a string between two indices.
|
|
54
167
|
* @param value - String value to slice.
|
|
@@ -146,4 +259,4 @@ declare function toUpperCase(value: string): string;
|
|
|
146
259
|
*/
|
|
147
260
|
declare function truncate(value: string, length: number, suffix?: string): string;
|
|
148
261
|
|
|
149
|
-
export { difference, filter, forEach, join, map, slice, sort, split, toCamelCase, toCapitalize, toKebabCase, toLowerCase, toPascalCase, toSentenceCase, toSlug, toSnakeCase, toTitleCase, toUpperCase, truncate };
|
|
262
|
+
export { difference, filter, forEach, freeze, isArray, isBigInt, isBoolean, isDate, isDefined, isEmpty, isFreeze, isFunction, isNumber, isObject, isString, isSymbol, isTruthy, isUndefined, join, map, merge, slice, sort, split, toCamelCase, toCapitalize, toKebabCase, toLowerCase, toPascalCase, toSentenceCase, toSlug, toSnakeCase, toTitleCase, toUpperCase, truncate };
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function l(e,t,r,s){const{symmetric:u=!1}=s??{};if(e.length===0&&t.length===0)return[];if(e.length===0)return u?[...t]:[];if(t.length===0)return[...e];if(!r){const o=new Set(t),n=e.filter(i=>!o.has(i));if(u){const i=new Set(e),f=t.filter(a=>!i.has(a));return[...n,...f]}return n}const c=e.filter(o=>!t.some(n=>r(o,n)));if(u){const o=t.filter(n=>!e.some(i=>r(n,i)));return[...c,...o]}return c}function p(e,t){return e.filter(t)}function g(e,t){e.forEach(t)}function h(e,t){return e.join(t)}function C(e,t){return e.map(t)}function y(e,t){return[...e].sort(t)}function b(e){return Array.isArray(e)}function m(e){return typeof e=="bigint"}function w(e){return typeof e=="boolean"}function A(e){return e instanceof Date}function j(e){return e!=null}function U(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:!1}function z(e){return typeof e=="object"&&e!==null&&Object.isFrozen(e)}function L(e){return typeof e=="function"}function S(e){return typeof e=="number"&&!Number.isNaN(e)}function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function d(e){return typeof e=="string"}function $(e){return typeof e=="symbol"}function N(e){return!!e}function O(e){return e===void 0}function D(e){return Object.freeze(e)}function E(e,t){return{...e,...t}}function F(e,t,r){return e.slice(t,r)}function Z(e,t,r){return e.split(t,r)}function k(e){return e.length===0?e:e.replace(/[-_\s]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^[A-Z]/,t=>t.toLowerCase())}function B(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function T(e){return e.length===0?e:e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}function v(e){return e.toLowerCase()}function x(e){return e.length===0?e:e.replace(/[-_\s]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^[a-z]/,t=>t.toUpperCase())}function I(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function K(e){return e.length===0?e:e.toLowerCase().replace(/[^\w\s-]/g,"").replace(/[\s_]+/g,"-").replace(/^-+|-+$/g,"").replace(/-+/g,"-")}function P(e){return e.length===0?e:e.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()}function q(e){return e.length===0?e:e.toLowerCase().replace(/(?:^|\s|-|_)\w/g,t=>t.toUpperCase())}function G(e){return e.toUpperCase()}function H(e,t,r="..."){return e.length<=t?e:t-r.length<=0?r.slice(0,t):e.slice(0,t-r.length)+r}export{l as difference,p as filter,g as forEach,D as freeze,b as isArray,m as isBigInt,w as isBoolean,A as isDate,j as isDefined,U as isEmpty,z as isFreeze,L as isFunction,S as isNumber,_ as isObject,d as isString,$ as isSymbol,N as isTruthy,O as isUndefined,h as join,C as map,E as merge,F as slice,y as sort,Z as split,k as toCamelCase,B as toCapitalize,T as toKebabCase,v as toLowerCase,x as toPascalCase,I as toSentenceCase,K as toSlug,P as toSnakeCase,q as toTitleCase,G as toUpperCase,H as truncate};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function l(e,t,r,a){const{symmetric:s=!1}=a??{};if(e.length===0&&t.length===0)return[];if(e.length===0)return s?[...t]:[];if(t.length===0)return[...e];if(!r){const o=new Set(t),n=e.filter(i=>!o.has(i));if(s){const i=new Set(e),c=t.filter(f=>!i.has(f));return[...n,...c]}return n}const u=e.filter(o=>!t.some(n=>r(o,n)));if(s){const o=t.filter(n=>!e.some(i=>r(n,i)));return[...u,...o]}return u}function p(e,t){return e.filter(t)}function g(e,t){e.forEach(t)}function C(e,t){return e.join(t)}function y(e,t){return e.map(t)}function h(e,t){return[...e].sort(t)}function b(e){return Array.isArray(e)}function m(e){return typeof e=="bigint"}function w(e){return typeof e=="boolean"}function A(e){return e instanceof Date}function S(e){return e!=null}function j(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:!1}function z(e){return typeof e=="object"&&e!==null&&Object.isFrozen(e)}function U(e){return typeof e=="function"}function d(e){return typeof e=="number"&&!Number.isNaN(e)}function L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function _(e){return typeof e=="string"}function D(e){return typeof e=="symbol"}function E(e){return!!e}function F(e){return e===void 0}function N(e){return Object.freeze(e)}function O(e,t){return{...e,...t}}function $(e,t,r){return e.slice(t,r)}function B(e,t,r){return e.split(t,r)}function T(e){return e.length===0?e:e.replace(/[-_\s]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^[A-Z]/,t=>t.toLowerCase())}function k(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function Z(e){return e.length===0?e:e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}function I(e){return e.toLowerCase()}function K(e){return e.length===0?e:e.replace(/[-_\s]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^[a-z]/,t=>t.toUpperCase())}function P(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function v(e){return e.length===0?e:e.toLowerCase().replace(/[^\w\s-]/g,"").replace(/[\s_]+/g,"-").replace(/^-+|-+$/g,"").replace(/-+/g,"-")}function q(e){return e.length===0?e:e.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()}function x(e){return e.length===0?e:e.toLowerCase().replace(/(?:^|\s|-|_)\w/g,t=>t.toUpperCase())}function G(e){return e.toUpperCase()}function H(e,t,r="..."){return e.length<=t?e:t-r.length<=0?r.slice(0,t):e.slice(0,t-r.length)+r}exports.difference=l,exports.filter=p,exports.forEach=g,exports.freeze=N,exports.isArray=b,exports.isBigInt=m,exports.isBoolean=w,exports.isDate=A,exports.isDefined=S,exports.isEmpty=j,exports.isFreeze=z,exports.isFunction=U,exports.isNumber=d,exports.isObject=L,exports.isString=_,exports.isSymbol=D,exports.isTruthy=E,exports.isUndefined=F,exports.join=C,exports.map=y,exports.merge=O,exports.slice=$,exports.sort=h,exports.split=B,exports.toCamelCase=T,exports.toCapitalize=k,exports.toKebabCase=Z,exports.toLowerCase=I,exports.toPascalCase=K,exports.toSentenceCase=P,exports.toSlug=v,exports.toSnakeCase=q,exports.toTitleCase=x,exports.toUpperCase=G,exports.truncate=H;
|
package/package.json
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pistachiojs/core",
|
|
3
|
-
"description": "-",
|
|
4
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"description": "Framework-agnostic TypeScript utility library with pure functions for common programming tasks",
|
|
4
|
+
"version": "0.2.0-dev.2",
|
|
5
5
|
"author": "Dirga Prakesha <dirga.prakesha@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dirgaprksha/pistachio.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/dirgaprksha/pistachio/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"utility",
|
|
17
|
+
"typescript",
|
|
18
|
+
"javascript",
|
|
19
|
+
"helpers",
|
|
20
|
+
"functional",
|
|
21
|
+
"framework-agnostic",
|
|
22
|
+
"type-safe",
|
|
23
|
+
"tree-shakeable",
|
|
24
|
+
"zero-dependencies"
|
|
25
|
+
],
|
|
7
26
|
"sideEffects": false,
|
|
8
27
|
"main": "dist/index.js",
|
|
9
28
|
"module": "dist/index.esm.js",
|