Skip to content

Commit 1a2754c

Browse files
committed
Merge branch 'array-object-split'
2 parents 2b3c041 + cca3b7f commit 1a2754c

104 files changed

Lines changed: 5057 additions & 6623 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
# Weser
1+
# WeserStack
22

33
A collection of packages that I use for building apps.<br />
44
This is a private collection and built solely to serve my use cases.<br />
5-
Documentation might be missing and APIs might be opinionated.<br />
6-
That said, all packages follow semver and you're free to use all of them.
75

8-
## Why?
6+
> *Note*: All packages follow semver starting with version 1.0.0.
97
10-
tbd.
8+
## [Documentation](https://stack.weser.io)
119

12-
## Packages
13-
14-
- [actions](/packages/actions)
15-
- [context](/packages/context)
16-
- [dnd](/packages/dnd)
17-
- [errors](/packages/errors)
18-
- [forms](/packages/forms)
19-
- [hooks](/packages/hooks)
20-
- [layers](/packages/layers)
21-
- [mdx](/packages/mdx)
22-
- [optimistic](/packages/optimistic)
23-
- [storage](/packages/storage)
24-
- [theming](/packages/theming)
2510

2611
## License
2712

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"private": true,
44
"packageManager": "pnpm@7.0.0",
55
"scripts": {
6-
"postinstall": "pnpm turbo run setup",
76
"build": "pnpm turbo run build",
87
"release": "pnpm prepare-release && lerna publish",
98
"pre-release": "pnpm prepare-release && lerna publish --dist-tag next --preid rc",

packages/array/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022-present Robin Weser
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.

packages/array/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @weser/array
2+
3+
[Documentation](https://packages.weser.io/array)

packages/array/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "@weser/array",
3+
"version": "1.0.0",
4+
"description": "Type-safe, performant & immutable array iteration utilities",
5+
"author": "Robin Weser <robin@weser.io>",
6+
"license": "MIT",
7+
"homepage": "https://github.com/robinweser/weser.git",
8+
"repository": "https://github.com/robinweser/weser.git",
9+
"type": "module",
10+
"main": "dist/index.js",
11+
"module": "dist/index.js",
12+
"types": "dist/index.d.ts",
13+
"sideEffects": false,
14+
"publishConfig": {
15+
"access": "public"
16+
},
17+
"files": [
18+
"LICENSE",
19+
"README.md",
20+
"dist/**"
21+
],
22+
"browserslist": [
23+
"IE >= 11",
24+
"Firefox >= 60",
25+
"Safari >= 11.1",
26+
"Chrome >= 66",
27+
"ChromeAndroid >= 66",
28+
"iOS >= 11.3",
29+
"Edge >= 15"
30+
],
31+
"scripts": {
32+
"setup": "pnpm build",
33+
"clean": "rimraf dist",
34+
"build": "tsc -b",
35+
"dev": "pnpm build -w",
36+
"test": "echo 1"
37+
},
38+
"keywords": [
39+
"array",
40+
"iteration",
41+
"map",
42+
"filter",
43+
"reduce",
44+
"utils"
45+
],
46+
"devDependencies": {
47+
"ava": "^6.1.3",
48+
"rimraf": "^3.0.2",
49+
"typescript": "^5.4.5"
50+
}
51+
}

packages/array/src/each.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function each<T>(
2+
arr: Array<T>,
3+
iterator: (value: T, index: number, length: number, array: Array<T>) => void
4+
) {
5+
for (let i = 0, len = arr.length; i < len; ++i) {
6+
iterator(arr[i], i, len, arr)
7+
}
8+
}

packages/array/src/filter.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function filter<T>(
2+
arr: Array<T>,
3+
filter: (value: T, index: number, length: number, array: Array<T>) => boolean
4+
) {
5+
const filteredArr = []
6+
7+
for (let i = 0, len = arr.length; i < len; ++i) {
8+
const value = arr[i]
9+
10+
if (filter(value, i, len, arr)) {
11+
filteredArr.push(value)
12+
}
13+
}
14+
15+
return filteredArr
16+
}

packages/array/src/groupBy.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function groupBy<T extends Record<string, any>>(
2+
arr: Array<T>,
3+
key: keyof T | ((item: T) => string)
4+
) {
5+
return arr.reduce(
6+
(grouped, item) => {
7+
const group = typeof key === 'function' ? key(item) : item[key]
8+
9+
grouped[group] = grouped[group] || []
10+
grouped[group].push(item)
11+
12+
return grouped
13+
},
14+
{} as Record<string, Array<T>>
15+
)
16+
}

packages/array/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export { default as each } from './each.js'
2+
export { default as filter } from './filter.js'
3+
export { default as groupBy } from './groupBy.js'
4+
export { default as map } from './map.js'
5+
export { default as reduce } from './reduce.js'
6+
export { default as unique } from './unique.js'

packages/array/src/map.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default function map<T>(
2+
arr: Array<T>,
3+
mapper: (value: T, index: number, length: number, array: Array<T>) => any
4+
) {
5+
const mappedArr = []
6+
7+
for (let i = 0, len = arr.length; i < len; ++i) {
8+
mappedArr.push(mapper(arr[i], i, len, arr))
9+
}
10+
11+
return mappedArr
12+
}

0 commit comments

Comments
 (0)