Skip to content

Commit 981bbce

Browse files
committed
initial
0 parents  commit 981bbce

File tree

14 files changed

+1430
-0
lines changed

14 files changed

+1430
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @vladkens

.github/funding.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: vladkens

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: "18"
15+
registry-url: "https://registry.npmjs.org"
16+
17+
- run: yarn install --frozen-lockfile
18+
- run: yarn test
19+
- run: yarn build
20+
21+
- run: npm publish
22+
env:
23+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
tags-ignore:
8+
- "v*"
9+
pull_request:
10+
workflow_dispatch:
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
node-version: [14, 16, 18, 20]
18+
name: node-${{ matrix.node-version }}
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-node@v3
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: "yarn"
25+
26+
- run: yarn install --frozen-lockfile
27+
- run: yarn format-check
28+
- run: yarn test-cov
29+
- run: yarn build

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
*.swp
10+
11+
pids
12+
logs
13+
results
14+
tmp
15+
16+
# Build
17+
public/css/main.css
18+
19+
# Coverage reports
20+
coverage
21+
22+
# API keys and secrets
23+
.env
24+
25+
# Dependency directory
26+
node_modules
27+
bower_components
28+
29+
# Editors
30+
.idea
31+
*.iml
32+
33+
# OS metadata
34+
.DS_Store
35+
Thumbs.db
36+
37+
# Ignore built ts files
38+
dist/**/*

.prettierrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"bracketSpacing": true,
3+
"printWidth": 100,
4+
"semi": false,
5+
"singleQuote": false,
6+
"tabWidth": 2,
7+
"trailingComma": "es5",
8+
"useTabs": false,
9+
"overrides": [
10+
{
11+
"files": "*.test.ts",
12+
"options": {
13+
"printWidth": 120
14+
}
15+
}
16+
]
17+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"prettier.prettierPath": "./node_modules/prettier",
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true,
5+
"files.exclude": {
6+
"coverage": true,
7+
"yarn.lock": true
8+
}
9+
}

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) 2023 vladkens
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.

package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"type": "module",
3+
"name": "array-utils-ts",
4+
"version": "0.1.0",
5+
"author": "Vlad Pronsky <[email protected]>",
6+
"repository": "vladkens/array-utils-ts",
7+
"description": "",
8+
"license": "MIT",
9+
"keywords": [],
10+
"files": [
11+
"dist"
12+
],
13+
"scripts": {
14+
"build": "rm -rf dist && pkgroll --minify && ls -lah dist",
15+
"test": "uvu -r tsm tests/",
16+
"test-cov": "c8 --include=src yarn test",
17+
"test-watch": "watchexec -e ts 'clear && yarn test'",
18+
"format": "prettier --write '{src,tests}/**/*.{js,jsx,ts,tsx}'",
19+
"format-check": "prettier --check '{src,tests}/**/*.{js,jsx,ts,tsx}'"
20+
},
21+
"dependencies": {},
22+
"devDependencies": {
23+
"c8": "^7.13.0",
24+
"pkgroll": "^1.10.0",
25+
"prettier": "^2.8.8",
26+
"prettier-plugin-organize-imports": "^3.2.2",
27+
"tsm": "^2.3.0",
28+
"typescript": "^5.0.4",
29+
"uvu": "^0.5.6"
30+
},
31+
"types": "./dist/main.d.cts",
32+
"exports": {
33+
"require": {
34+
"types": "./dist/main.d.cts",
35+
"default": "./dist/main.cjs"
36+
},
37+
"import": {
38+
"types": "./dist/main.d.mts",
39+
"default": "./dist/main.mjs"
40+
}
41+
}
42+
}

readme.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# array-utils-ts
2+
3+
<div align="center">
4+
<a href="https://npmjs.org/package/array-utils-ts">
5+
<img src="https://badgen.net/npm/v/array-utils-ts" alt="version" />
6+
</a>
7+
<a href="https://github.com/vladkens/array-utils-ts/actions">
8+
<img src="https://github.com/vladkens/array-utils-ts/workflows/test/badge.svg" alt="test status" />
9+
</a>
10+
<a href="https://packagephobia.now.sh/result?p=array-utils-ts">
11+
<img src="https://badgen.net/packagephobia/publish/array-utils-ts" alt="size" />
12+
</a>
13+
<!-- <a href="https://npmjs.org/package/array-utils-ts">
14+
<img src="https://badgen.net/npm/dm/array-utils-ts" alt="downloads" />
15+
</a> -->
16+
<a href="https://github.com/vladkens/array-utils-ts/blob/main/LICENSE">
17+
<img src="https://badgen.net/github/license/vladkens/array-utils-ts" alt="license" />
18+
</a>
19+
</div>
20+
21+
A set of functions for working with arrays, often necessary for working with state, but absent in lodash.
22+
23+
## Install
24+
25+
```sh
26+
yarn add array-utils-ts
27+
```
28+
29+
## Usage
30+
31+
### filterNullable
32+
33+
```typescript
34+
import { filterNullable } from "array-utils-ts"
35+
36+
filterNullable([1, null, 2, undefined])
37+
// -> [1, 2]
38+
```
39+
40+
### filterEmpty
41+
42+
```typescript
43+
import { filterEmpty } from "array-utils-ts"
44+
45+
filterEmpty([1, null, 2, undefined, 3, "", "a"])
46+
// -> [1, 2, 3, "a"]
47+
```
48+
49+
### isUniq
50+
51+
```typescript
52+
import { isUniq } from "array-utils-ts"
53+
54+
isUniq([1, 2, 3])
55+
// -> true
56+
57+
isUniq([1, 2, 1])
58+
// -> false
59+
```
60+
61+
### hasEmpty
62+
63+
```typescript
64+
import { hasEmpty } from "array-utils-ts"
65+
66+
hasEmpty(["a", "b", "c"])
67+
// -> false
68+
69+
hasEmpty(["a", "", "c"])
70+
// -> true
71+
72+
hasEmpty(["a", undefined, "c"])
73+
// -> true
74+
```
75+
76+
### toggleItem
77+
78+
For example useful in `<select>` component
79+
80+
```typescript
81+
import { toggleItem } from "array-utils-ts"
82+
83+
toggleItem([1, 2, 3], 4)
84+
// -> [1, 2, 3, 4]
85+
86+
toggleItem([1, 2, 3], 3)
87+
// -> [1, 2]
88+
```
89+
90+
### replaceItem
91+
92+
```typescript
93+
import { replaceItem } from "array-utils-ts"
94+
95+
toggleItem([1, 2, 3], 4)
96+
// -> [1, 2, 3, 4]
97+
98+
toggleItem([1, 2, 3], 3)
99+
// -> [1, 2]
100+
```
101+
102+
### updateByKey
103+
104+
```typescript
105+
import { updateByKey } from "array-utils-ts"
106+
107+
const arr = [{ id: 1 }, { id: 2 }]
108+
109+
updateByKey([1, 2, 3], 4)
110+
// -> [1, 2, 3, 4]
111+
112+
updateByKey([1, 2, 3], 3)
113+
// -> [1, 2]
114+
```

0 commit comments

Comments
 (0)