Skip to content

Commit

Permalink
Remove lodash dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfbarr committed Nov 27, 2022
1 parent c59e0b9 commit 5e2a9e5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
React hook for logging per component lifecycle

## Features
- 🪶 **Lightweight** — under *500B* gzipped
- 🪶 **Lightweight** — under *1Kb* gzipped
- 🗂️ **Typed** — made with TypeScript, ships with types
- 🥰 **Simple** — don't worry about any changes in your props & state
- 🔧 **Customizable** — work in progress 😉
- 🔬 **Tested** — up to 100% coverage
- 🏎️ **Fast** — native react hooks & optimized
- 📭 **Minimal dependecies** — only some lodash functions
- 📭 **No dependecies**



Expand Down
18 changes: 15 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,5 @@
"path": "dist/module.js",
"limit": "1 kB"
}
],
"dependencies": {
"lodash": "^4.17.21"
}
]
}
34 changes: 16 additions & 18 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cloneDeep from 'lodash/cloneDeep'
import { useEffect, useRef } from 'react'

const CSS_COMPONENT = 'color: DodgerBlue'
Expand All @@ -23,23 +22,22 @@ export enum PrintTypes {
}

export function useLog(): UseLogReturn {
const componentName = (function getComponentName() {
try {
throw new Error()
} catch (error) {
if (error instanceof Error) {
const re = /(\w+)@|at (\w+) \(/g

re.exec(error?.stack ?? '')
re.exec(error?.stack ?? '')
const m = re.exec(error?.stack ?? '') ?? []

return String(m[1] || m[2])
const componentName =
(function getComponentName() {
try {
throw new Error()
} catch (error) {
if (error instanceof Error) {
const re = /(\w+)@|at (\w+) \(/g

re.exec(error?.stack ?? '')
re.exec(error?.stack ?? '')
const m = re.exec(error?.stack ?? '') ?? []

return String(m[1] || m[2])
}
}

return ''
}
})()
})() ?? ''

const getGroupLabel = (type: PrintTypes): string => {
return `${String(type)} ${
Expand All @@ -59,7 +57,7 @@ export function useLog(): UseLogReturn {
}

function log<T>(value: T): void {
const clonedValue = cloneDeep(value)
const clonedValue = JSON.parse(JSON.stringify(value))

return (() => {
const isUnmounting = useRef(false)
Expand Down

0 comments on commit 5e2a9e5

Please sign in to comment.