Gathering detailed insights and metrics for use-fns
Gathering detailed insights and metrics for use-fns
Gathering detailed insights and metrics for use-fns
Gathering detailed insights and metrics for use-fns
chartjs-adapter-date-fns
Chart.js adapter to use date-fns for time functionalities
babel-plugin-date-fns
> :warning: The current version (2.x) supports date-fns v2. If you are using v1, please use [1.x](https://github.com/date-fns/babel-plugin-date-fns/tree/v1).
use-lilius
A headless calendar hook for React.
plugins
Run a value through a plugin stack.
npm install use-fns
Typescript
Module System
Node Version
NPM Version
55.6
Supply Chain
98.9
Quality
75.9
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
3,380
Last Day
1
Last Week
11
Last Month
42
Last Year
458
2 Stars
94 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.27
Package Id
use-fns@1.0.27
Unpacked Size
40.21 kB
Size
9.12 kB
File Count
6
NPM Version
6.14.16
Node Version
14.19.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-56%
11
Compared to previous week
Last month
180%
42
Compared to previous month
Last year
-28.5%
458
Compared to previous year
Some utility functions prefixed with use
$ npm i use-fns
1import fns from "use-fns";
Determine the type of variable
1declare function useTypeOf(v: any): string;
1import { useTypeOf } from 'use-fns' 2console.log(useTypeOf('abc')) // 'string' 3console.log(useTypeOf(123)) // 'number' 4console.log(useTypeOf(true)) // 'boolean' 5console.log(useTypeOf(null)) // 'null' 6console.log(useTypeOf(undefined)) // 'undefined' 7console.log(useTypeOf(Symbol())) // 'symbol' 8console.log(useTypeOf(BigInt())) // 'bigint' 9console.log(useTypeOf([])) // 'array' 10console.log(useTypeOf({})) // 'object' 11console.log(useTypeOf(/.+/)) // 'regexp' 12console.log(useTypeOf(new Date())) // 'date' 13...
Calling a function multiple times only takes the last one as the result
1declare function useDebounce(cb: Function, wait: number = 500): Function;
1import { useDebounce } from "use-fns"; 2const cb = () => console.log("useDebounce"); 3const newCb = useDebounce(cb, 1000); 4for (let i = 0; i < 10; i++) newCb(); // only call once after one second
Call the function at regular intervals
1declare function useThrottle(cb: Function, wait: number = 500): Function;
1import { useThrottle } from "use-fns"; 2const cb = () => console.log("useDebounce"); 3const newCb = useThrottle(cb, 1000); 4for (let i = 0; i < 10; i++) newCb(); // call the function per second
Desensitization of mobile phone number(not strict)
1declare function useHideMobile(s: string): string;
1import { useHideMobile } from "use-fns"; 2const phoneNumber = useHideMobile("12345678911"); // 1*********1
Launch full screen
1declare function useLaunchFullscreen<T extends Element>(ele: T): void;
1import { useLaunchFullscreen } from "use-fns"; 2useLaunchFullscreen(document.body);
Exit full screen
1declare function useExitFullscreen(): void;
1import { useExitFullscreen } from "use-fns"; 2useExitFullscreen();
Convert string case
1declare function useTurnCase(str: string, type: number): void;
1import { useTurnCase } from "use-fns"; 2const upper = useTurnCase("aBc", 1); // ABC 3const lower = useTurnCase("aBc", 2); // abc 4const capital = useTurnCase("aBc", 3); // ABc 5const original = useTurnCase("aBc", 4); // aBc
Get url search params
1declare function useSearchParams(): Record<string, string>;
1import { useSearchParams } from "use-fns"; 2// if location.search = '?a=1&b=2' 3const params = useSearchParams(); // {a: 1,b: 2}
Get current terminal type
1declare function useSysType(): void;
1import { useSysType } from "use-fns"; 2const sys = useSysType(); // 'ios' | 'android' | ''
Array objects are deduplicated according to fields
1declare function useUniqueArrObj<T extends Record<string, any>, U extends T[]>( 2 arr: U, 3 k: keyof T 4): void;
1import { useUniqueArrObj } from "use-fns"; 2const uniqueArr = useUniqueArrObj( 3 [ 4 { name: "Joruno", age: 22 }, 5 { name: "hanchen", age: 22 }, 6 { name: "old man", age: 21 }, 7 ], 8 "age" 9); 10 11/** 12 * [ 13 * {name: 'Joruno', age: 22}, 14 * {name: 'old man', age: 21}, 15 * ] 16 */
Scroll to top of page
1declare function useScrollToTop(): void;
1import { useScrollToTop } from "use-fns"; 2useScrollToTop();
Scroll to element position
1declare function useSmoothScroll(selector: string = "body"): void;
1import { useSmoothScroll } from "use-fns"; 2useSmoothScroll("#form");
Generate uuid
1declare function useUUID(): void;
1import { useUUID } from "use-fns"; 2const uuid = useUUID(); // 'e728a1e4-dd9c-4e3f-a747-8ca67985e293'
Money format
1declare function useMoneyFormat(): void;
1import { useMoneyFormat } from "use-fns"; 2const res = useMoneyFormat();
automatic serialization localStorage
1declare function useLocalCache(): void;
1import { useLocalCache } from "use-fns"; 2const local = useLocalCache(); 3local.setItem("person", { name: "Joruno", age: 22 }); 4local.getItem("person"); 5local.removeItem("person"); 6local.clear(); 7local.key(0); 8local.length();
automatic serialization sessionStorage
1declare function useSessionCache(): void;
1import { useSessionCache } from "use-fns"; 2const session = useSessionCache(); 3session.setItem("person", { name: "Joruno", age: 22 }); 4session.getItem("person"); 5session.removeItem("person"); 6session.clear(); 7session.key(0); 8session.length();
Fuzz query
1declare function useFuzzyQuery<T extends Record<string, any>, U extends T[]>( 2 list: U, 3 keyWord: string, 4 attr: keyof T 5): void;
1import { useFuzzyQuery } from "use-fns"; 2useFuzzyQuery( 3 [ 4 { name: "Joruno", age: 22 }, 5 { name: "hanchen", age: 22 }, 6 { name: "old man", age: 21 }, 7 ], 8 "o", 9 "name" 10); 11 12/** 13 * [ 14 * {name: 'Joruno', age: 22}, 15 * {name: 'old man', age: 21}, 16 * ] 17 */
foreach all tree node
1declare function useForeachTree<T extends Record<string, any>>(data: T[],cb: Function, childrenName:keyof T): void;
1import { useForeachTree } from "use-fns"; 2useForeachTree( 3 [ 4 { 5 name: "Joruno", 6 age: 22, 7 children: [ 8 { 9 name: "hanchen", 10 age: 22 11 }, 12 { 13 name: "old man", 14 age: 21 15 } 16 ] 17 } 18 ], 19 console.log, 20 'children' 21); 22 23/** 24 * 25 * { 26 * name: 'Joruno', 27 * age: 22, 28 * children: [ 29 * { name: 'hanchen', age: 22 }, 30 * { name: 'old man', age: 21 } 31 * ] 32 * }, 33 * 34 * { name: 'hanchen', age: 22 }, 35 * 36 * { name: 'old man', age: 21 } 37 * 38 */
Get the number of characters in a string
1declare function useCharacterCount(s: string, char: string): number;
1import { useCharacterCount } from "use-fns"; 2const count = useCharacterCount('Joruno','o') // 2
Check if object is empty
1declare function useIsEmptyObj<T extends Record<string, any>(obj: T): boolean;
1import { useIsEmptyObj } from "use-fns"; 2useIsEmptyObj({}) // true 3useIsEmptyObj({a: 1}) // false
Wait for a while before calling function
1declare function useDelay(ms: number): Promise<void>;
1import { useDelay } from "use-fns"; 2await useDelay(1000) // Wait for one second
Get the day difference between two dates
1declare function useDaysBetween(d1:number, d2: number): number;
1import { useDaysBetween } from "use-fns"; 2const timeStamp = Date.now() 3useDaysBetween(timeStamp,timeStamp + 3600 * 1000 * 24 * 7) // 7
Redirect to another URL
1declare function useRedirect(url: string): string;
1import { useRedirect } from "use-fns";
2useRedirect('https://github.com') // Redirect to github
Check for touch support on your device
1declare function useTouchSupported(): boolean;
1import { useTouchSupported } from "use-fns"; 2useTouchSupported() // true or false
Insert HTML string after element
1declare function useInsertHTMLAfter(html: string, el: Element): void;
1import { useInsertHTMLAfter } from "use-fns";
2useInsertHTMLAfter('<div>useInsertHTMLAfter</div>',document.body)
Shuffle array
1declare function useShuffle(arr: any[]): any[];
1import { useShuffle } from "use-fns"; 2useShuffle([1,2]) // [1,2] or [2,1]
Get selected text on webpage
1declare function useGetSelectedText(): string;
1import { useGetSelectedText } from "use-fns"; 2useGetSelectedText()
Get random boolean
1declare function useGetRandomBoolean(): boolean;
1import { useGetRandomBoolean } from "use-fns"; 2useGetRandomBoolean() // true or false
Calculate the sum of an array
1declare function useSum(arr: any[]): number;
1import { useSum } from "use-fns"; 2useSum([]) // 0 3useSum([1,2]) // 3 4useSum([1,2,3]) // 6
Calculate the average of an array
1declare function useAverage(arr: any[]): number;
1import { useAverage } from "use-fns"; 2useAverage([]) // 0 3useAverage([1,2]) // 1.5 4useAverage([1,2,3]) // 2
Determine if a string is a valid URL
1declare function useIsUrl(arr: any[],opts: {readonly lenient?: boolean} = {lenient: false}): boolean;
1import { useIsUrl } from "use-fns";
2useIsUrl('https://github.com') // true
3useIsUrl('github.com') // false;
4useIsUrl('github.com',{lenient: true}) // true
Convert git address to github address
1declare function useGithubUrlFromGit(url: string,opts: Record<string,any> = {}): string;
1import { useGithubUrlFromGit } from "use-fns";
2useGithubUrlFromGit('git+https://github.com/Joruno-w/use-fns.git') // https://github.com/Joruno-w/use-fns
Check if a string is npm scoped
1declare function useIsScoped(s: string): boolean;
1import { useIsScoped } from "use-fns";
2useIsScoped('@joruno/use-fns') // true
3useIsScoped('joruno/use-fns') // false
Swap two elements of an array (mutable)
1declare function useArrayMoveMutable(arr: unknow[],fromIndex: number,toIndex: number): void;
1import { useArrayMoveMutable } from "use-fns"; 2useArrayMoveMutable([1,2,3],0,2) // [3,2,1] 3useArrayMoveMutable([1,2,3],0,-2) // [2,1,3]
Swap two elements of an array (immutable)
1declare function useArrayMoveImmutable(arr: unknow[],fromIndex: number,toIndex: number): void;
1import { useArrayMoveImmutable } from "use-fns"; 2useArrayMoveImmutable([1,2,3],0,2) // [3,2,1] 3useArrayMoveImmutable([1,2,3],0,-2) // [2,1,3]
No vulnerabilities found.
No security vulnerabilities found.