Skip to content

Commit

Permalink
Merge pull request #9 from clickbar/update-deps
Browse files Browse the repository at this point in the history
chore: Update dependencies & format
  • Loading branch information
djfhe authored Oct 8, 2023
2 parents 0adec2a + ae3bc48 commit 6dbc799
Show file tree
Hide file tree
Showing 16 changed files with 1,302 additions and 1,183 deletions.
10 changes: 0 additions & 10 deletions .eslintrc.cjs

This file was deleted.

8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"root": true,
"extends": ["@clickbar/typescript"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"unicorn/no-array-reduce": "off"
}
}
4 changes: 2 additions & 2 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Changelog Enforcer"
name: 'Changelog Enforcer'
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
# Enforces the update of a changelog file on every pull request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
name: Fix styling
name: Linting and formatting

on: [push]

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
fix-styling:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 7

- uses: actions/setup-node@v3
with:
Expand All @@ -27,9 +29,8 @@ jobs:
# `pnpm rebuild` will run all those post-install scripts for us.
- run: pnpm rebuild && pnpm run --if-present prepare

- run: pnpm fix
- name: Run ESLint
run: pnpm lint

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
- name: Run prettier
run: pnpm prettier --check
13 changes: 7 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ name: Tests

on: [push]

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 7

- uses: actions/setup-node@v3
with:
Expand All @@ -28,4 +30,3 @@ jobs:
- run: pnpm rebuild && pnpm run --if-present prepare

- run: pnpm test

6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/.git
**/.svn
**/.hg
**/node_modules

pnpm-lock.yaml
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"tabWidth": 2
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to **dot-diver** will be documented here. Inspired by [keep

## Unreleased

- Updated dependencies
- Formatted code with new lint rules
- Fixed testcase for new TypeScript behavior

## [1.0.1](https://github.com/clickbar/dot-diver/tree/1.0.1) (2023-03-26)

- Rerelease with content 😅

## [1.0.0](https://github.com/clickbar/dot-diver/tree/1.0.0) (2023-03-26)

- Initial Release 🎉

1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ If the project maintainer has any additional requirements, you will find them li

**Happy coding**!


-- Thanks to [Spatie](https://github.com/spatie) for these contributing guidelines & their packages.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A lightweight, powerful, and dependency-free TypeScript utility library that pro
Dot notation is a popular and convenient way to access deeply nested properties in objects. With Dot Diver, you can safely work with object paths in TypeScript projects, ensuring type correctness and productivity!

Example:

```typescript
import { getByPath } from '@clickbar/dot-diver'

Expand All @@ -14,6 +15,7 @@ const object = {

const result = getByPath(object, 'a') // result is 'Hello world'
```

<br>

## 🌟 Features
Expand Down Expand Up @@ -192,26 +194,26 @@ import { getByPath, setByPath } from '@clickbar/dot-diver'

import type { Path, SearchableObject, PathValue } from '@clickbar/dot-diver'

function getByPathDepth10<T extends SearchableObject, P extends Path<T, 5> & string>(
function getByPathDepth5<T extends SearchableObject, P extends Path<T, 5> & string>(
object: T,
path: P
path: P,
): PathValue<T, P, 5> {
return getByPath(object, path) as PathValue<T, P, 5>
}

function setByPathDepth10<
function setByPathDepth5<
T extends SearchableObject,
P extends Path<T, 5> & string,
V extends PathValue<T, P, 5>
V extends PathValue<T, P, 5>,
>(object: T, path: P, value: V): void {
setByPath(object, path, value as PathValue<T, P, 10>)
setByPath(object, path, value as PathValue<T, P>)
}

export { getByPathDepth10 as getByPath, setByPathDepth10 as setByPath }
export { getByPathDepth5 as getByPath, setByPathDepth5 as setByPath }
```

The intersection between `Path<T, 5>` and `string` is necessary for TypeScript to successfully narrow down the type of `P` based on the user-provided `path` input.
Without the intersection, the `path` would just be of type `Path<T, 10>` and `PathValueEntry` would be a union of all possible return types.
Without the intersection, the `path` would just be of type `Path<T, 5>` and `PathValueEntry` would be a union of all possible return types.
By using the intersection, TypeScript is forced to apply the `Path` constraints and infer the type from the provided user input.

<br>
Expand Down
3 changes: 0 additions & 3 deletions eslintrc.json

This file was deleted.

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@clickbar/dot-diver",
"version": "1.0.1",
"description": "Types and utilities to access object properties by dot notation.",
"packageManager": "[email protected]",
"types": "dist/index.d.ts",
"exports": {
".": {
Expand All @@ -19,7 +20,9 @@
"build": "vite build",
"test": "vitest run && vitest typecheck --run",
"lint": "eslint ./ --ext=js,ts",
"fix": "eslint ./ --ext=js,ts --fix"
"prettier": "prettier . --cache",
"fix": "pnpm lint --fix && pnpm format",
"format": "pnpm prettier --write"
},
"keywords": [
"ts",
Expand All @@ -43,12 +46,12 @@
"Tobias Kröll <[email protected]> (https://github.com/saibotk)"
],
"devDependencies": {
"@clickbar/eslint-config-typescript": "^4.3.0",
"eslint": "^8.36.0",
"prettier": "^2.8.7",
"typescript": "^5.0.2",
"vite": "^4.2.1",
"vite-plugin-dts": "^2.1.0",
"vitest": "^0.29.7"
"@clickbar/eslint-config-typescript": "^9.0.1",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vite-plugin-dts": "^3.6.0",
"vitest": "^0.34.6"
}
}
}
Loading

0 comments on commit 6dbc799

Please sign in to comment.