dogu-utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/.eslintrc ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "node": true
5
+ },
6
+ "extends": ["eslint:recommended"],
7
+ "parserOptions": {
8
+ "ecmaVersion": 2021
9
+ },
10
+ "rules": {
11
+ // Add your custom rules here
12
+ }
13
+ }
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "printWidth": 80,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": false,
6
+ "singleQuote": false,
7
+ "trailingComma": "none",
8
+ "bracketSpacing": true,
9
+ "arrowParens": "avoid"
10
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "dogu-utils",
3
+ "version": "0.0.1",
4
+ "description": "A utility library for TypeScript, JavaScript",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "build": "rollup -c",
11
+ "watch": "rollup -cw"
12
+ },
13
+ "keywords": [],
14
+ "author": "Jeon Jaewon <wksk3249@gmail.com>",
15
+ "repository": "https://github.com/JeonJaewon/dogu-utils.git",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@babel/core": "^7.24.4",
19
+ "@babel/preset-env": "^7.24.4",
20
+ "@babel/preset-react": "^7.24.1",
21
+ "@babel/preset-typescript": "^7.24.1",
22
+ "@rollup/plugin-babel": "^6.0.4",
23
+ "@rollup/plugin-typescript": "^11.1.6",
24
+ "@types/react": "^18.2.74",
25
+ "@types/react-dom": "^18.2.24",
26
+ "eslint": "^9.0.0",
27
+ "prettier": "^3.2.5",
28
+ "tslib": "^2.6.2",
29
+ "typescript": "^5.4.4"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^18.2.0"
33
+ }
34
+ }
@@ -0,0 +1,23 @@
1
+ import babel from "@rollup/plugin-babel";
2
+ import typescript from "@rollup/plugin-typescript";
3
+
4
+ export default {
5
+ input: "./src/index.ts",
6
+ output: {
7
+ file: "./dist/index.js",
8
+ format: "es",
9
+ sourcemap: true,
10
+ },
11
+ plugins: [
12
+ babel({
13
+ babelHelpers: "bundled",
14
+ presets: [
15
+ "@babel/preset-env",
16
+ "@babel/preset-react",
17
+ "@babel/preset-typescript",
18
+ ],
19
+ extensions: [".js", ".jsx", ".ts", ".tsx"],
20
+ }),
21
+ typescript(),
22
+ ],
23
+ };
package/src/Hello.tsx ADDED
@@ -0,0 +1,6 @@
1
+ import React from "react"
2
+ import ReactDOM from "react-dom"
3
+
4
+ export const Hello = () => {
5
+ return <div>Hello World!</div>
6
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./react"
@@ -0,0 +1,10 @@
1
+ import { useCallback, useState } from "react"
2
+
3
+ export const useOpenCloseState = (initialState = false) => {
4
+ const [isOpen, setIsOpen] = useState(initialState)
5
+
6
+ const open = useCallback(() => setIsOpen(true), [])
7
+ const close = useCallback(() => setIsOpen(false), [])
8
+
9
+ return [isOpen, open, close] as const
10
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./hooks/useOpenCloseState"
2
+ export * from "./utils/createSafeContext"
@@ -0,0 +1,26 @@
1
+ import { ReactNode, createContext, useContext } from "react"
2
+
3
+ type ProviderProps<Value> = {
4
+ children: ReactNode
5
+ value: Value
6
+ }
7
+
8
+ export const createSafeContext = <Value,>(defaultValue?: Value) => {
9
+ const Context = createContext<Value | null>(defaultValue ?? null)
10
+
11
+ const Provider = ({ children, value }: ProviderProps<Value>) => {
12
+ return <Context.Provider value={value}>{children}</Context.Provider>
13
+ }
14
+
15
+ const useSafeContext = () => {
16
+ const context = useContext(Context)
17
+ if (context === null) {
18
+ throw new Error(
19
+ "useSafeContext must be used within a Provider, or give it a default value."
20
+ )
21
+ }
22
+ return context
23
+ }
24
+
25
+ return [Provider, useSafeContext] as const
26
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "lib": ["dom", "esnext"],
5
+ "jsx": "react-jsx",
6
+ "module": "es6",
7
+ "moduleResolution": "node",
8
+ "baseUrl": "./",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "declaration": true,
12
+ "declarationDir": "./dist"
13
+ }
14
+ }