Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vueuse/shared

Package Overview
Dependencies
Maintainers
1
Versions
237
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vueuse/shared - npm Package Compare versions

Comparing version 4.0.0-rc.9 to 4.0.0-rc.10

66

dist/index.cjs.js

@@ -557,11 +557,5 @@ 'use strict';

/**
* Promised one-time watch for ref changes
* @param r ref or watch source
* @param options
*/
function when(r, rootOptions = {}) {
function when(r) {
let isNot = false;
function toMatch(condition, options = {}) {
const { flush = 'pre', timeout = 0, throwOnTimeout = false, } = Object.assign(Object.assign({}, rootOptions), options);
function toMatch(condition, { flush = 'sync', timeout, throwOnTimeout } = {}) {
let stop = null;

@@ -581,4 +575,5 @@ const watcher = new Promise((resolve) => {

if (timeout) {
promises.push(promiseTimeout(timeout, throwOnTimeout)
.finally(() => { stop === null || stop === void 0 ? void 0 : stop(); }));
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
stop === null || stop === void 0 ? void 0 : stop();
}));
}

@@ -588,3 +583,3 @@ return Promise.race(promises);

function toBe(value, options) {
return toMatch(v => v === value, options);
return toMatch(v => v === vueDemi.unref(value), options);
}

@@ -603,6 +598,6 @@ function toBeTruthy(options) {

}
function toContain(value, options) {
function toContains(value, options) {
return toMatch((v) => {
const array = Array.from(v);
return array.includes(value);
return array.includes(value) || array.includes(vueDemi.unref(value));
}, options);

@@ -620,17 +615,32 @@ }

}
return {
toMatch,
toBe,
toBeTruthy,
toBeNull,
toBeNaN,
toBeUndefined,
toContain,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
if (Array.isArray(vueDemi.unref(r))) {
const instance = {
toMatch,
toContains,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
return instance;
}
else {
const instance = {
toMatch,
toBe,
toBeTruthy,
toBeNull,
toBeNaN,
toBeUndefined,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
return instance;
}
}

@@ -637,0 +647,0 @@

@@ -1,2 +0,2 @@

import { Ref, WatchSource, ComputedRef as ComputedRef$1, WatchOptions, WatchCallback, WatchStopHandle, ShallowUnwrapRef } from 'vue-demi';
import { Ref, WatchSource, ComputedRef as ComputedRef$1, WatchOptions, WatchCallback, WatchStopHandle, ShallowUnwrapRef as ShallowUnwrapRef$1 } from 'vue-demi';
import { ComputedRef, WatchStopHandle as WatchStopHandle$1, Ref as Ref$1 } from 'vue-demi';

@@ -36,2 +36,4 @@

declare type MaybeRef<T> = T | Ref<T> | ComputedRef$1<T>;
declare type ElementOf<T> = T extends (infer E)[] ? E : never;
declare type ShallowUnwrapRef<T> = T extends Ref<infer P> ? P : T;
interface Pausable {

@@ -140,3 +142,3 @@ /**

*/
declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R, extend: Extend, options: Options): ShallowUnwrapRef<Extend> & R;
declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R, extend: Extend, options: Options): ShallowUnwrapRef$1<Extend> & R;
/**

@@ -325,3 +327,3 @@ * Overlad 2: Unwrap unset or set to true

interface WhenToMatchOptions extends ConfigurableFlush {
interface WhenToMatchOptions {
/**

@@ -340,7 +342,17 @@ * Milseconds timeout for promise to resolve/reject if the when condition does not meet.

throwOnTimeout?: boolean;
/**
* `flush` option for internal watch
*
* @default 'sync'
*/
flush?: WatchOptions['flush'];
}
interface WhenInstance<T> {
readonly not: WhenInstance<T>;
toMatch(condition: (v: T | object) => boolean, options?: WhenToMatchOptions): Promise<void>;
toBe<P>(value: P | T, options?: WhenToMatchOptions): Promise<void>;
interface BaseWhenInstance<T> {
toMatch(condition: (v: T) => boolean, options?: WhenToMatchOptions): Promise<void>;
changed(options?: WhenToMatchOptions): Promise<void>;
changedTimes(n?: number, options?: WhenToMatchOptions): Promise<void>;
}
interface ValueWhenInstance<T> extends BaseWhenInstance<T> {
readonly not: ValueWhenInstance<T>;
toBe<P = T>(value: MaybeRef<T | P>, options?: WhenToMatchOptions): Promise<void>;
toBeTruthy(options?: WhenToMatchOptions): Promise<void>;

@@ -350,13 +362,12 @@ toBeNull(options?: WhenToMatchOptions): Promise<void>;

toBeNaN(options?: WhenToMatchOptions): Promise<void>;
toContain<P>(value: P, options?: WhenToMatchOptions): Promise<void>;
changed(options?: WhenToMatchOptions): Promise<void>;
changedTimes(n?: number, options?: WhenToMatchOptions): Promise<void>;
}
/**
* Promised one-time watch for ref changes
* @param r ref or watch source
* @param options
*/
declare function when<T>(r: WatchSource<T> | object, rootOptions?: WhenToMatchOptions): WhenInstance<T>;
interface ArrayWhenInstance<T> extends BaseWhenInstance<T> {
readonly not: ArrayWhenInstance<T>;
toContains(value: MaybeRef<ElementOf<ShallowUnwrapRef<T>>>, options?: WhenToMatchOptions): Promise<void>;
}
declare function when<T extends unknown[]>(r: T): ArrayWhenInstance<T>;
declare function when<T extends Ref<unknown[]>>(r: T): ArrayWhenInstance<T>;
declare function when<T>(r: WatchSource<T>): ValueWhenInstance<T>;
declare function when<T>(r: T): ValueWhenInstance<T>;
export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, DebouncedWatchOptions, EventFilter, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnReturn, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, SyncRefOptions, ThrottledWatchOptions, WatchWithFilterOptions, WhenInstance, WhenToMatchOptions, assert, biSyncRef, bypassFilter, clamp, controlledComputed, createFilterWrapper, debounceFilter, debouncedWatch, extendRef, ignorableWatch, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, pausableFilter, pausableWatch, promiseTimeout, syncRef, throttleFilter, throttledWatch, timestamp, tryOnMounted, tryOnUnmounted, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchWithFilter, when };
export { ArrayWhenInstance, BaseWhenInstance, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, DebouncedWatchOptions, ElementOf, EventFilter, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnReturn, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, ShallowUnwrapRef, SyncRefOptions, ThrottledWatchOptions, ValueWhenInstance, WatchWithFilterOptions, WhenToMatchOptions, assert, biSyncRef, bypassFilter, clamp, controlledComputed, createFilterWrapper, debounceFilter, debouncedWatch, extendRef, ignorableWatch, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, pausableFilter, pausableWatch, promiseTimeout, syncRef, throttleFilter, throttledWatch, timestamp, tryOnMounted, tryOnUnmounted, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchWithFilter, when };

@@ -1,2 +0,2 @@

import { watch, ref, computed, isRef, getCurrentInstance, onMounted, nextTick, onUnmounted } from 'vue-demi';
import { watch, ref, computed, isRef, getCurrentInstance, onMounted, nextTick, onUnmounted, unref } from 'vue-demi';

@@ -553,11 +553,5 @@ /**

/**
* Promised one-time watch for ref changes
* @param r ref or watch source
* @param options
*/
function when(r, rootOptions = {}) {
function when(r) {
let isNot = false;
function toMatch(condition, options = {}) {
const { flush = 'pre', timeout = 0, throwOnTimeout = false, } = Object.assign(Object.assign({}, rootOptions), options);
function toMatch(condition, { flush = 'sync', timeout, throwOnTimeout } = {}) {
let stop = null;

@@ -577,4 +571,5 @@ const watcher = new Promise((resolve) => {

if (timeout) {
promises.push(promiseTimeout(timeout, throwOnTimeout)
.finally(() => { stop === null || stop === void 0 ? void 0 : stop(); }));
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
stop === null || stop === void 0 ? void 0 : stop();
}));
}

@@ -584,3 +579,3 @@ return Promise.race(promises);

function toBe(value, options) {
return toMatch(v => v === value, options);
return toMatch(v => v === unref(value), options);
}

@@ -599,6 +594,6 @@ function toBeTruthy(options) {

}
function toContain(value, options) {
function toContains(value, options) {
return toMatch((v) => {
const array = Array.from(v);
return array.includes(value);
return array.includes(value) || array.includes(unref(value));
}, options);

@@ -616,19 +611,34 @@ }

}
return {
toMatch,
toBe,
toBeTruthy,
toBeNull,
toBeNaN,
toBeUndefined,
toContain,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
if (Array.isArray(unref(r))) {
const instance = {
toMatch,
toContains,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
return instance;
}
else {
const instance = {
toMatch,
toBe,
toBeTruthy,
toBeNull,
toBeNaN,
toBeUndefined,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
return instance;
}
}
export { assert, biSyncRef, bypassFilter, clamp, controlledComputed, createFilterWrapper, debounceFilter, debouncedWatch, extendRef, ignorableWatch, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, pausableFilter, pausableWatch, promiseTimeout, syncRef, throttleFilter, throttledWatch, timestamp, tryOnMounted, tryOnUnmounted, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchWithFilter, when };

@@ -557,11 +557,5 @@ (function (global, factory) {

/**
* Promised one-time watch for ref changes
* @param r ref or watch source
* @param options
*/
function when(r, rootOptions = {}) {
function when(r) {
let isNot = false;
function toMatch(condition, options = {}) {
const { flush = 'pre', timeout = 0, throwOnTimeout = false, } = Object.assign(Object.assign({}, rootOptions), options);
function toMatch(condition, { flush = 'sync', timeout, throwOnTimeout } = {}) {
let stop = null;

@@ -581,4 +575,5 @@ const watcher = new Promise((resolve) => {

if (timeout) {
promises.push(promiseTimeout(timeout, throwOnTimeout)
.finally(() => { stop === null || stop === void 0 ? void 0 : stop(); }));
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
stop === null || stop === void 0 ? void 0 : stop();
}));
}

@@ -588,3 +583,3 @@ return Promise.race(promises);

function toBe(value, options) {
return toMatch(v => v === value, options);
return toMatch(v => v === vueDemi.unref(value), options);
}

@@ -603,6 +598,6 @@ function toBeTruthy(options) {

}
function toContain(value, options) {
function toContains(value, options) {
return toMatch((v) => {
const array = Array.from(v);
return array.includes(value);
return array.includes(value) || array.includes(vueDemi.unref(value));
}, options);

@@ -620,17 +615,32 @@ }

}
return {
toMatch,
toBe,
toBeTruthy,
toBeNull,
toBeNaN,
toBeUndefined,
toContain,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
if (Array.isArray(vueDemi.unref(r))) {
const instance = {
toMatch,
toContains,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
return instance;
}
else {
const instance = {
toMatch,
toBe,
toBeTruthy,
toBeNull,
toBeNaN,
toBeUndefined,
changed,
changedTimes,
get not() {
isNot = !isNot;
return this;
},
};
return instance;
}
}

@@ -637,0 +647,0 @@

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["VueUseShared utilities"]={},e.VueDemi)}(this,(function(e,t){"use strict";function n(e,t){var n={};for(var u in e)Object.prototype.hasOwnProperty.call(e,u)&&t.indexOf(u)<0&&(n[u]=e[u]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(u=Object.getOwnPropertySymbols(e);r<u.length;r++)t.indexOf(u[r])<0&&Object.prototype.propertyIsEnumerable.call(e,u[r])&&(n[u[r]]=e[u[r]])}return n}const u="undefined"!=typeof window,r=Object.prototype.toString;function o(e,t){return function(...n){e((()=>t.apply(this,n)),{fn:t,thisArg:this,args:n})}}const i=e=>e();function c(e){if(e<=0)return i;let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function s(e,t=!0){if(e<=0)return i;let n,u=0;const r=()=>{n&&(clearTimeout(n),n=void 0)};return o=>{const i=Date.now()-u;r(),i>e?(u=Date.now(),o()):t&&(n=setTimeout((()=>{r(),o()}),e))}}function l(e=i){const n=t.ref(!0);return{isActive:n,pause:function(){n.value=!1},resume:function(){n.value=!0},eventFilter:(...t)=>{n.value&&e(...t)}}}function a(e,t=!1,n="Timeout"){return new Promise(((u,r)=>{t?setTimeout((()=>r(n)),e):setTimeout(u,e)}))}function f(e,u,r={}){const{eventFilter:c=i}=r,s=n(r,["eventFilter"]);return t.watch(e,o(c,u),s)}function v(e){t.getCurrentInstance()&&t.onUnmounted(e)}function d(e,t=200){return o(c(t),e)}function p(e,n=1e3,u=!0){let r=null;const o=t.ref(!1);function i(){r&&(clearInterval(r),r=null)}function c(){o.value=!1,i()}function s(){o.value=!0,i(),r=setInterval(e,n)}return u&&s(),v(c),{isActive:o,pause:c,resume:s,start:s,stop:c}}function m(e,t=200,n=!0){return o(s(t,n),e)}function h(e,n,u){const r=t.ref(!1);let o=null;function i(){o&&(clearTimeout(o),o=null)}function c(){r.value=!1,i()}function s(){i(),r.value=!0,o=setTimeout((()=>{o=null,e()}),n)}return u&&s(),v(c),{isActive:r,start:s,stop:c}}e.assert=(e,...t)=>{e||console.warn(...t)},e.biSyncRef=function(e,n){const u="sync",r=t.watch(e,(e=>{n.value=e}),{flush:u,immediate:!0}),o=t.watch(n,(t=>{e.value=t}),{flush:u,immediate:!0});return()=>{r(),o()}},e.bypassFilter=i,e.clamp=(e,t,n)=>Math.min(n,Math.max(t,e)),e.controlledComputed=function(e,n){const u=t.ref(n());return t.watch(e,(()=>u.value=n()),{flush:"sync"}),t.computed((()=>u.value))},e.createFilterWrapper=o,e.debounceFilter=c,e.debouncedWatch=function(e,t,u={}){const{debounce:r=0}=u,o=n(u,["debounce"]);return f(e,t,Object.assign(Object.assign({},o),{eventFilter:c(r)}))},e.extendRef=function(e,n,{enumerable:u=!1,unwrap:r=!0}={}){for(const[o,i]of Object.entries(n))"value"!==o&&(t.isRef(i)&&r?Object.defineProperty(e,o,{get:()=>i.value,set(e){i.value=e},enumerable:u}):Object.defineProperty(e,o,{value:i,enumerable:u}));return e},e.ignorableWatch=function(e,u,r={}){const{eventFilter:c=i}=r,s=n(r,["eventFilter"]),l=o(c,u);let a,f,v;if("sync"===s.flush){const n=t.ref(!1);f=()=>{},a=e=>{n.value=!0,e(),n.value=!1},v=t.watch(e,((...e)=>{n.value||l(...e)}),s)}else{const n=[],u=t.ref(0),r=t.ref(0);f=()=>{u.value=r.value},n.push(t.watch(e,(()=>{r.value++}),Object.assign(Object.assign({},s),{flush:"sync"}))),a=e=>{const t=r.value;e(),u.value+=r.value-t},n.push(t.watch(e,((...e)=>{const t=u.value>0&&u.value===r.value;u.value=0,r.value=0,t||l(...e)}),s)),v=()=>{n.forEach((e=>e()))}}return{stop:v,ignoreUpdates:a,ignorePrevAsyncUpdates:f}},e.invoke=function(e){return e()},e.isBoolean=e=>"boolean"==typeof e,e.isClient=u,e.isDef=e=>void 0!==e,e.isFunction=e=>"function"==typeof e,e.isNumber=e=>"number"==typeof e,e.isObject=e=>"[object Object]"===r.call(e),e.isString=e=>"string"==typeof e,e.isWindow=e=>"undefined"!=typeof window&&"[object Window]"===r.call(e),e.makeDestructurable=function(e,t){if("undefined"!=typeof Symbol){const n=Object.assign({},e);return Object.defineProperty(n,Symbol.iterator,{enumerable:!1,value(){let e=0;return{next:()=>({value:t[e++],done:e>t.length})}}}),n}return Object.assign([...t],e)},e.noop=()=>{},e.now=()=>Date.now(),e.pausableFilter=l,e.pausableWatch=function(e,t,u={}){const{eventFilter:r}=u,o=n(u,["eventFilter"]),{eventFilter:i,pause:c,resume:s,isActive:a}=l(r);return{stop:f(e,t,Object.assign(Object.assign({},o),{eventFilter:i})),pause:c,resume:s,isActive:a}},e.promiseTimeout=a,e.syncRef=function(e,n,{flush:u="sync",deep:r=!1,immediate:o=!0}={}){return Array.isArray(n)||(n=[n]),t.watch(e,(e=>{n.forEach((t=>t.value=e))}),{flush:u,deep:r,immediate:o})},e.throttleFilter=s,e.throttledWatch=function(e,t,u={}){const{throttle:r=0}=u,o=n(u,["throttle"]);return f(e,t,Object.assign(Object.assign({},o),{eventFilter:s(r)}))},e.timestamp=()=>+Date.now(),e.tryOnMounted=function(e,n=!0){t.getCurrentInstance()?t.onMounted(e):n?e():t.nextTick(e)},e.tryOnUnmounted=v,e.useCounter=function(e=0){const n=t.ref(e),u=e=>n.value=e;return{count:n,inc:(e=1)=>n.value+=e,dec:(e=1)=>n.value-=e,get:()=>n.value,set:u,reset:(t=e)=>(e=t,u(t))}},e.useDebounce=function(e,n=200){if(n<=0)return e;const u=t.ref(e.value),r=d((()=>{u.value=e.value}),n);return t.watch(e,(()=>r())),u},e.useDebounceFn=d,e.useInterval=function(e=1e3,n=!0){const u=t.ref(0);return Object.assign({counter:u},p((()=>u.value+=1),e,n))},e.useIntervalFn=p,e.useThrottle=function(e,n=200){if(n<=0)return e;const u=t.ref(e.value),r=m((()=>{u.value=e.value}),n);return t.watch(e,(()=>r())),u},e.useThrottleFn=m,e.useTimeout=function(e=1e3,n=!0){const u=t.ref(!1),r=h((()=>u.value=!0),e,n);return{ready:u,isActive:r.isActive,start:function(){u.value=!1,r.start()},stop:function(){u.value=!1,r.stop()}}},e.useTimeoutFn=h,e.useToggle=function(e=!1){const n=t.ref(e);return[n,()=>n.value=!n.value]},e.watchWithFilter=f,e.when=function(e,n={}){let u=!1;function r(r,o={}){const{flush:i="pre",timeout:c=0,throwOnTimeout:s=!1}=Object.assign(Object.assign({},n),o);let l=null;const f=[new Promise((n=>{l=t.watch(e,(e=>{r(e)===!u&&(null==l||l(),n())}),{flush:i,immediate:!0})}))];return c&&f.push(a(c,s).finally((()=>{null==l||l()}))),Promise.race(f)}function o(e,t){return r((t=>t===e),t)}function i(e=1,t){let n=-1;return r((()=>(n+=1,n>=e)),t)}return{toMatch:r,toBe:o,toBeTruthy:function(e){return r((e=>Boolean(e)),e)},toBeNull:function(e){return o(null,e)},toBeNaN:function(e){return r(Number.isNaN,e)},toBeUndefined:function(e){return o(void 0,e)},toContain:function(e,t){return r((t=>Array.from(t).includes(e)),t)},changed:function(e){return i(1,e)},changedTimes:i,get not(){return u=!u,this}}},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["VueUseShared utilities"]={},e.VueDemi)}(this,(function(e,t){"use strict";function n(e,t){var n={};for(var u in e)Object.prototype.hasOwnProperty.call(e,u)&&t.indexOf(u)<0&&(n[u]=e[u]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(u=Object.getOwnPropertySymbols(e);r<u.length;r++)t.indexOf(u[r])<0&&Object.prototype.propertyIsEnumerable.call(e,u[r])&&(n[u[r]]=e[u[r]])}return n}const u="undefined"!=typeof window,r=Object.prototype.toString;function o(e,t){return function(...n){e((()=>t.apply(this,n)),{fn:t,thisArg:this,args:n})}}const i=e=>e();function c(e){if(e<=0)return i;let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function s(e,t=!0){if(e<=0)return i;let n,u=0;const r=()=>{n&&(clearTimeout(n),n=void 0)};return o=>{const i=Date.now()-u;r(),i>e?(u=Date.now(),o()):t&&(n=setTimeout((()=>{r(),o()}),e))}}function l(e=i){const n=t.ref(!0);return{isActive:n,pause:function(){n.value=!1},resume:function(){n.value=!0},eventFilter:(...t)=>{n.value&&e(...t)}}}function a(e,t=!1,n="Timeout"){return new Promise(((u,r)=>{t?setTimeout((()=>r(n)),e):setTimeout(u,e)}))}function f(e,u,r={}){const{eventFilter:c=i}=r,s=n(r,["eventFilter"]);return t.watch(e,o(c,u),s)}function v(e){t.getCurrentInstance()&&t.onUnmounted(e)}function d(e,t=200){return o(c(t),e)}function m(e,n=1e3,u=!0){let r=null;const o=t.ref(!1);function i(){r&&(clearInterval(r),r=null)}function c(){o.value=!1,i()}function s(){o.value=!0,i(),r=setInterval(e,n)}return u&&s(),v(c),{isActive:o,pause:c,resume:s,start:s,stop:c}}function p(e,t=200,n=!0){return o(s(t,n),e)}function h(e,n,u){const r=t.ref(!1);let o=null;function i(){o&&(clearTimeout(o),o=null)}function c(){r.value=!1,i()}function s(){i(),r.value=!0,o=setTimeout((()=>{o=null,e()}),n)}return u&&s(),v(c),{isActive:r,start:s,stop:c}}e.assert=(e,...t)=>{e||console.warn(...t)},e.biSyncRef=function(e,n){const u="sync",r=t.watch(e,(e=>{n.value=e}),{flush:u,immediate:!0}),o=t.watch(n,(t=>{e.value=t}),{flush:u,immediate:!0});return()=>{r(),o()}},e.bypassFilter=i,e.clamp=(e,t,n)=>Math.min(n,Math.max(t,e)),e.controlledComputed=function(e,n){const u=t.ref(n());return t.watch(e,(()=>u.value=n()),{flush:"sync"}),t.computed((()=>u.value))},e.createFilterWrapper=o,e.debounceFilter=c,e.debouncedWatch=function(e,t,u={}){const{debounce:r=0}=u,o=n(u,["debounce"]);return f(e,t,Object.assign(Object.assign({},o),{eventFilter:c(r)}))},e.extendRef=function(e,n,{enumerable:u=!1,unwrap:r=!0}={}){for(const[o,i]of Object.entries(n))"value"!==o&&(t.isRef(i)&&r?Object.defineProperty(e,o,{get:()=>i.value,set(e){i.value=e},enumerable:u}):Object.defineProperty(e,o,{value:i,enumerable:u}));return e},e.ignorableWatch=function(e,u,r={}){const{eventFilter:c=i}=r,s=n(r,["eventFilter"]),l=o(c,u);let a,f,v;if("sync"===s.flush){const n=t.ref(!1);f=()=>{},a=e=>{n.value=!0,e(),n.value=!1},v=t.watch(e,((...e)=>{n.value||l(...e)}),s)}else{const n=[],u=t.ref(0),r=t.ref(0);f=()=>{u.value=r.value},n.push(t.watch(e,(()=>{r.value++}),Object.assign(Object.assign({},s),{flush:"sync"}))),a=e=>{const t=r.value;e(),u.value+=r.value-t},n.push(t.watch(e,((...e)=>{const t=u.value>0&&u.value===r.value;u.value=0,r.value=0,t||l(...e)}),s)),v=()=>{n.forEach((e=>e()))}}return{stop:v,ignoreUpdates:a,ignorePrevAsyncUpdates:f}},e.invoke=function(e){return e()},e.isBoolean=e=>"boolean"==typeof e,e.isClient=u,e.isDef=e=>void 0!==e,e.isFunction=e=>"function"==typeof e,e.isNumber=e=>"number"==typeof e,e.isObject=e=>"[object Object]"===r.call(e),e.isString=e=>"string"==typeof e,e.isWindow=e=>"undefined"!=typeof window&&"[object Window]"===r.call(e),e.makeDestructurable=function(e,t){if("undefined"!=typeof Symbol){const n=Object.assign({},e);return Object.defineProperty(n,Symbol.iterator,{enumerable:!1,value(){let e=0;return{next:()=>({value:t[e++],done:e>t.length})}}}),n}return Object.assign([...t],e)},e.noop=()=>{},e.now=()=>Date.now(),e.pausableFilter=l,e.pausableWatch=function(e,t,u={}){const{eventFilter:r}=u,o=n(u,["eventFilter"]),{eventFilter:i,pause:c,resume:s,isActive:a}=l(r);return{stop:f(e,t,Object.assign(Object.assign({},o),{eventFilter:i})),pause:c,resume:s,isActive:a}},e.promiseTimeout=a,e.syncRef=function(e,n,{flush:u="sync",deep:r=!1,immediate:o=!0}={}){return Array.isArray(n)||(n=[n]),t.watch(e,(e=>{n.forEach((t=>t.value=e))}),{flush:u,deep:r,immediate:o})},e.throttleFilter=s,e.throttledWatch=function(e,t,u={}){const{throttle:r=0}=u,o=n(u,["throttle"]);return f(e,t,Object.assign(Object.assign({},o),{eventFilter:s(r)}))},e.timestamp=()=>+Date.now(),e.tryOnMounted=function(e,n=!0){t.getCurrentInstance()?t.onMounted(e):n?e():t.nextTick(e)},e.tryOnUnmounted=v,e.useCounter=function(e=0){const n=t.ref(e),u=e=>n.value=e;return{count:n,inc:(e=1)=>n.value+=e,dec:(e=1)=>n.value-=e,get:()=>n.value,set:u,reset:(t=e)=>(e=t,u(t))}},e.useDebounce=function(e,n=200){if(n<=0)return e;const u=t.ref(e.value),r=d((()=>{u.value=e.value}),n);return t.watch(e,(()=>r())),u},e.useDebounceFn=d,e.useInterval=function(e=1e3,n=!0){const u=t.ref(0);return Object.assign({counter:u},m((()=>u.value+=1),e,n))},e.useIntervalFn=m,e.useThrottle=function(e,n=200){if(n<=0)return e;const u=t.ref(e.value),r=p((()=>{u.value=e.value}),n);return t.watch(e,(()=>r())),u},e.useThrottleFn=p,e.useTimeout=function(e=1e3,n=!0){const u=t.ref(!1),r=h((()=>u.value=!0),e,n);return{ready:u,isActive:r.isActive,start:function(){u.value=!1,r.start()},stop:function(){u.value=!1,r.stop()}}},e.useTimeoutFn=h,e.useToggle=function(e=!1){const n=t.ref(e);return[n,()=>n.value=!n.value]},e.watchWithFilter=f,e.when=function(e){let n=!1;function u(u,{flush:r="sync",timeout:o,throwOnTimeout:i}={}){let c=null;const s=[new Promise((o=>{c=t.watch(e,(e=>{u(e)===!n&&(null==c||c(),o())}),{flush:r,immediate:!0})}))];return o&&s.push(a(o,i).finally((()=>{null==c||c()}))),Promise.race(s)}function r(e,n){return u((n=>n===t.unref(e)),n)}function o(e){return i(1,e)}function i(e=1,t){let n=-1;return u((()=>(n+=1,n>=e)),t)}if(Array.isArray(t.unref(e))){return{toMatch:u,toContains:function(e,n){return u((n=>{const u=Array.from(n);return u.includes(e)||u.includes(t.unref(e))}),n)},changed:o,changedTimes:i,get not(){return n=!n,this}}}return{toMatch:u,toBe:r,toBeTruthy:function(e){return u((e=>Boolean(e)),e)},toBeNull:function(e){return r(null,e)},toBeNaN:function(e){return u(Number.isNaN,e)},toBeUndefined:function(e){return r(void 0,e)},changed:o,changedTimes:i,get not(){return n=!n,this}}},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@vueuse/shared",
"version": "4.0.0-rc.9",
"version": "4.0.0-rc.10",
"main": "dist/index.cjs.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc