@yanglee2421/utils 0.0.0-stage → 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 yanglee2421
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ export declare const arrayFromLength: (length: number) => number[];
2
+ type CallbackFn<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn;
3
+ /**
4
+ * Polyfill for `Array.prototype.groupBy` method, which is not yet widely supported.
5
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/groupBy
6
+ */
7
+ export declare const mapGroupBy: <TElement, TKey>(items: TElement[], callbackFn: CallbackFn<[TElement, number], TKey>) => Map<TKey, TElement[]>;
8
+ export {};
package/dist/index.mjs ADDED
@@ -0,0 +1,21 @@
1
+ // src/array-from-length.ts
2
+ const arrayFromLength = (length) => {
3
+ return Array.from({ length }, (_, index) => index + 1);
4
+ };
5
+ // src/map-group-by.ts
6
+ /**
7
+ * Polyfill for `Array.prototype.groupBy` method, which is not yet widely supported.
8
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/groupBy
9
+ */
10
+ const mapGroupBy = (items, callbackFn) => {
11
+ const resultMap = /* @__PURE__ */ new Map();
12
+ items.reduce((latestResult, item, index) => {
13
+ const mapKey = callbackFn(item, index);
14
+ const mapValue = latestResult.get(mapKey);
15
+ if (Array.isArray(mapValue)) mapValue.push(item);
16
+ else latestResult.set(mapKey, [item]);
17
+ return latestResult;
18
+ }, resultMap);
19
+ return resultMap;
20
+ };
21
+ export { arrayFromLength, mapGroupBy };
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@yanglee2421/utils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "A lightweight, modern, and type-safe JavaScript/TypeScript utility library.",
5
+ "keywords": [
6
+ "utils",
7
+ "toolkit",
8
+ "helpers",
9
+ "typescript",
10
+ "javascript",
11
+ "zero-dependency"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "yanglee2421",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/yanglee2421/yanglee2421.git",
18
+ "directory": "/packages/utils"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/yanglee2421/yanglee2421/issues"
22
+ },
23
+ "homepage": "https://github.com/yanglee2421/yanglee2421/blob/main/README.md",
24
+ "private": false,
25
+ "type": "module",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "exports": {
30
+ "import": "./dist/index.mjs",
31
+ "types": "./dist/index.d.mts"
32
+ },
33
+ "scripts": {
34
+ "dev": "vpx --watch ./src/index.ts",
35
+ "build": "vp pack"
36
+ }
6
37
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.