📄 useCounter¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 6 |
| 📦 Imports | 5 |
| 📐 Interfaces | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/shared/useCounter/index.ts
📦 Imports¶
| Name | Source |
|---|---|
MaybeRef |
vue |
Ref |
vue |
shallowReadonly |
vue |
shallowRef |
vue |
unref |
vue |
Functions¶
useCounter(initialValue: MaybeRef<number>, options: UseCounterOptions): { count: any; inc: (delta?: number) => number; dec: (delta?…¶
Basic counter with utility functions.
Parameters:
initialValueany(optional): No descriptionoptionsany: No description
See: https://vueuse.org/useCounter
Raw JSDoc
Calls:
unref (from vue)shallowRef (from vue)Math.maxMath.minsetshallowReadonly (from vue)
Code
export function useCounter(initialValue: MaybeRef<number> = 0, options: UseCounterOptions = {}) {
let _initialValue = unref(initialValue)
const count = shallowRef(initialValue)
const {
max = Number.POSITIVE_INFINITY,
min = Number.NEGATIVE_INFINITY,
} = options
const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min)
const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max)
const get = () => count.value
const set = (val: number) => (count.value = Math.max(min, Math.min(max, val)))
const reset = (val = _initialValue) => {
_initialValue = val
return set(val)
}
return { count: shallowReadonly(count), inc, dec, get, set, reset }
}
Internal helpers¶
Declared inside another function in this file.
inc(delta: number): number¶
Parameters:
deltanumber
Returns: number
dec(delta: number): number¶
Parameters:
deltanumber
Returns: number
get(): any¶
Returns: any
set(val: number): number¶
Parameters:
valnumber
Returns: number
reset(val: any): number¶
Parameters:
valany
Returns: number
Calls:
set
Interfaces¶
UseCounterOptions¶
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
min |
number |
✓ | not shown |
max |
number |
✓ | not shown |
UseCounterReturn¶
Interface Code
export interface UseCounterReturn {
/**
* The current value of the counter.
*/
readonly count: Readonly<Ref<number>>
/**
* Increment the counter.
*
* @param {number} [delta=1] The number to increment.
*/
inc: (delta?: number) => void
/**
* Decrement the counter.
*
* @param {number} [delta=1] The number to decrement.
*/
dec: (delta?: number) => void
/**
* Get the current value of the counter.
*/
get: () => number
/**
* Set the counter to a new value.
*
* @param val The new value of the counter.
*/
set: (val: number) => void
/**
* Reset the counter to an initial value.
*/
reset: (val?: number) => number
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
count |
Readonly<Ref<number>> |
✗ | not shown |
inc |
(delta?: number) => void |
✗ | not shown |
dec |
(delta?: number) => void |
✗ | not shown |
get |
() => number |
✗ | not shown |
set |
(val: number) => void |
✗ | not shown |
reset |
(val?: number) => number |
✗ | not shown |
Generated by Syntax Scribe