Skip to content

Commit

Permalink
Merge pull request #5 from Renna-Labs/v1.1.4
Browse files Browse the repository at this point in the history
dependency: update eslint config extension
  • Loading branch information
echoghi authored Feb 3, 2023
2 parents ed99dcc + b98bf4f commit 49ebd38
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 239 deletions.
35 changes: 7 additions & 28 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
module.exports = {
extends: ['@rennalabs/eslint-config/react', 'plugin:@typescript-eslint/recommended'],
plugins: ['@typescript-eslint'],
env: {
browser: true,
es2021: true,
node: true,
},
parser: '@typescript-eslint/parser',
root: true,
extends: ['./node_modules/@rennalabs/tsconfig'],
parserOptions: {
ecmaVersion: 13,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
project: './tsconfig.json',
},
rules: {
// eslint rules
'no-use-before-define': 'off',
'prefer-rest-params': 'off',
'no-param-reassign': 'off',
'no-void': 'off',
'react/react-in-jsx-scope': 'off',
'react-hooks/exhaustive-deps': 'off',
'@typescript-eslint/no-implied-eval': 'off',
'consistent-return': 'off',
'no-restricted-syntax': 'off',
'arrow-body-style': 'off',
'no-console': 'off',
'no-undef': 'off',
'prefer-arrow-callback': 'off',
// react rules
'react/prop-types': 'off',
// typescript rules
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'prefer-rest-params': 'off',
},
};
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rennalabs/hooks",
"version": "1.1.3",
"version": "1.1.4",
"description": "A library of useful hooks.",
"main": "dist/index.js",
"typings": "types/index.d.ts",
Expand All @@ -13,6 +13,7 @@
"build": "NODE_ENV=production npm run clean && babel ./src --out-dir ./dist --ignore \"src/**/*.test.ts\",\"src/**/*.test.tsx\" --extensions \".ts,.tsx\" && tsc",
"clean": "rimraf types dist",
"format": "prettier --write \"src/*.{js,ts,tsx,json,md}\"",
"lint": "eslint \"src/**/*.{js,ts,tsx}\" --quiet",
"test": "jest",
"test:watch": "jest --watch",
"prepare": "husky install",
Expand Down Expand Up @@ -83,18 +84,22 @@
"@babel/preset-typescript": "^7.x.x",
"@rennalabs/eslint-config": "^1.0.2",
"@rennalabs/prettier-config": "1.0.3",
"@rennalabs/tsconfig": "1.0.1",
"@rennalabs/tsconfig": "1.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.27",
"@typescript-eslint/eslint-plugin": "^5.x.x",
"@typescript-eslint/parser": "^5.x.x",
"eslint": "^7.x.x",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^8.18.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.x.x",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
Expand Down
28 changes: 15 additions & 13 deletions src/useElementSize/useElementSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ export function useResizeObserver<T extends HTMLElement = any>() {
() =>
typeof window !== 'undefined'
? new ResizeObserver((entries: any) => {
const entry = entries[0];

if (entry) {
cancelAnimationFrame(frameID.current);

frameID.current = requestAnimationFrame(() => {
if (ref.current) {
setRect(entry.contentRect);
}
});
}
})
const entry = entries[0];

if (entry) {
cancelAnimationFrame(frameID.current);

frameID.current = requestAnimationFrame(() => {
if (ref.current) {
setRect(entry.contentRect);
}
});
}
})
: null,
[],
);
Expand All @@ -45,7 +45,9 @@ export function useResizeObserver<T extends HTMLElement = any>() {
}

return () => {
if (observer) {observer.disconnect();}
if (observer) {
observer.disconnect();
}

if (frameID.current) {
cancelAnimationFrame(frameID.current);
Expand Down
16 changes: 12 additions & 4 deletions src/useFullscreen/useFullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ function getFullscreenElement(): HTMLElement | null {
async function exitFullscreen() {
const _document = window.document as any;

if (typeof _document.exitFullscreen === 'function') {return _document.exitFullscreen();}
if (typeof _document.msExitFullscreen === 'function') {return _document.msExitFullscreen();}
if (typeof _document.webkitExitFullscreen === 'function') {return _document.webkitExitFullscreen();}
if (typeof _document.mozCancelFullScreen === 'function') {return _document.mozCancelFullScreen();}
if (typeof _document.exitFullscreen === 'function') {
return _document.exitFullscreen();
}
if (typeof _document.msExitFullscreen === 'function') {
return _document.msExitFullscreen();
}
if (typeof _document.webkitExitFullscreen === 'function') {
return _document.webkitExitFullscreen();
}
if (typeof _document.mozCancelFullScreen === 'function') {
return _document.mozCancelFullScreen();
}

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/useWindowScrollPosition/useWindowScrollPosition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';
import { throttle } from '../utils';

interface ScrollPosition {
Expand Down
2 changes: 1 addition & 1 deletion src/useWindowSize/useWindowSize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';
import { throttle } from '../utils';

const events = new Set<() => void>();
Expand Down
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export function throttle<T extends(...args: any[]) => void>(
export function throttle<T extends (...args: any[]) => void>(
func: T,
threshold = 250,
scope?: any,
): T {
let last: number;
let deferTimer: number;
return function(this: any) {
return function (this: any) {
const context = scope || this;

const now = Date.now();
Expand All @@ -14,7 +14,7 @@ export function throttle<T extends(...args: any[]) => void>(
// hold on to it
clearTimeout(deferTimer);
// @ts-ignore
deferTimer = setTimeout(function() {
deferTimer = setTimeout(() => {
last = now;
// @ts-ignore
func.apply(context, args);
Expand All @@ -40,9 +40,9 @@ export const isClient: boolean = typeof window === 'object';
/**
* Clamps a given value within a specified range.
*/
export function clamp(value: number, min: number, max: number) {
export const clamp = (value: number, min: number, max: number) => {
return Math.min(Math.max(value, min), max);
}
};

// Utility helper for random number generation
export const random = (min: number, max: number) => Math.floor(Math.random() * (max - min)) + min;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"outDir": "./types",
"emitDeclarationOnly": true
},
"include": ["**/*.ts", "**/*.tsx"],
"include": ["**/*.ts", "**/*.tsx", ".eslintrc.js"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 49ebd38

Please sign in to comment.