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

@vueuse/core

Package Overview
Dependencies
Maintainers
1
Versions
358
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vueuse/core - npm Package Compare versions

Comparing version 2.0.0-alpha.11 to 2.0.0-alpha.12

dist/esm/useStorage/index.d.ts

4

dist/esm/index.d.ts

@@ -5,4 +5,2 @@ export { init } from './api';

export * from './useIntervalFn';
export * from './useLocalStorage';
export * from './useLocalStoragePlain';
export * from './useMouse';

@@ -13,2 +11,4 @@ export * from './useNetwork';

export * from './useRaf';
export * from './useStorage';
export * from './useStoragePlain';
export * from './useTimeout';

@@ -15,0 +15,0 @@ export * from './useTimeoutFn';

@@ -5,4 +5,2 @@ export { init } from './api';

export * from './useIntervalFn';
export * from './useLocalStorage';
export * from './useLocalStoragePlain';
export * from './useMouse';

@@ -13,2 +11,4 @@ export * from './useNetwork';

export * from './useRaf';
export * from './useStorage';
export * from './useStoragePlain';
export * from './useTimeout';

@@ -15,0 +15,0 @@ export * from './useTimeoutFn';

@@ -5,4 +5,2 @@ export { init } from './api';

export * from './useIntervalFn';
export * from './useLocalStorage';
export * from './useLocalStoragePlain';
export * from './useMouse';

@@ -13,2 +11,4 @@ export * from './useNetwork';

export * from './useRaf';
export * from './useStorage';
export * from './useStoragePlain';
export * from './useTimeout';

@@ -15,0 +15,0 @@ export * from './useTimeoutFn';

@@ -11,4 +11,2 @@ "use strict";

__export(require("./useIntervalFn"));
__export(require("./useLocalStorage"));
__export(require("./useLocalStoragePlain"));
__export(require("./useMouse"));

@@ -19,2 +17,4 @@ __export(require("./useNetwork"));

__export(require("./useRaf"));
__export(require("./useStorage"));
__export(require("./useStoragePlain"));
__export(require("./useTimeout"));

@@ -21,0 +21,0 @@ __export(require("./useTimeoutFn"));

@@ -112,48 +112,2 @@ (function (global, factory) {

function useLocalStoragePlain(key, defaultValue) {
var data = CompositionAPI.ref(defaultValue);
try {
var localStorageValue = localStorage.getItem(key);
if (!localStorageValue) {
if (defaultValue)
localStorage.setItem(key, defaultValue);
}
else {
data.value = localStorageValue || undefined;
}
}
catch (e) {
console.warn(e);
}
CompositionAPI.watch(data, function () {
try {
if (data.value == null)
localStorage.removeItem(key);
else
localStorage.setItem(key, data.value);
}
catch (e) {
console.warn(e);
}
}, { flush: 'sync', lazy: true });
return data;
}
function useLocalStorage(key, defaultValue) {
function stringify(data) {
return data ? JSON.stringify(data) : '';
}
function parse(str) {
return str ? JSON.parse(str) : (defaultValue || {});
}
var plain = useLocalStoragePlain(key, stringify(defaultValue));
var state = CompositionAPI.ref(parse(plain.value));
function update() {
plain.value = stringify(state.value);
}
CompositionAPI.watch(plain, function () { return state.value = parse(plain.value); }, { flush: 'sync', lazy: true });
CompositionAPI.watch(state, update, { flush: 'sync', lazy: true });
return { state: state, update: update };
}
function useMouse(refEl) {

@@ -335,2 +289,50 @@ if (refEl === void 0) { refEl = CompositionAPI.ref(null); }

function useStoragePlain(key, defaultValue, storage) {
if (storage === void 0) { storage = localStorage; }
var data = CompositionAPI.ref(defaultValue);
try {
var rawValue = storage.getItem(key);
if (!rawValue) {
if (defaultValue)
storage.setItem(key, defaultValue);
}
else {
data.value = rawValue || undefined;
}
}
catch (e) {
console.warn(e);
}
CompositionAPI.watch(data, function () {
try {
if (data.value == null)
storage.removeItem(key);
else
storage.setItem(key, data.value);
}
catch (e) {
console.warn(e);
}
}, { flush: 'sync', lazy: true });
return data;
}
function useStorage(key, defaultValue, storage) {
if (storage === void 0) { storage = localStorage; }
function stringify(data) {
return data ? JSON.stringify(data) : '';
}
function parse(str) {
return str ? JSON.parse(str) : (defaultValue || {});
}
var plain = useStoragePlain(key, stringify(defaultValue), storage);
var state = CompositionAPI.ref(parse(plain.value));
function update() {
plain.value = stringify(state.value);
}
CompositionAPI.watch(plain, function () { return state.value = parse(plain.value); }, { flush: 'sync', lazy: true });
CompositionAPI.watch(state, update, { flush: 'sync', lazy: true });
return { state: state, update: update };
}
function useWindowScroll() {

@@ -375,4 +377,2 @@ var x = CompositionAPI.ref(isClient ? window.pageXOffset : 0);

exports.useIntervalFn = useIntervalFn;
exports.useLocalStorage = useLocalStorage;
exports.useLocalStoragePlain = useLocalStoragePlain;
exports.useMouse = useMouse;

@@ -383,2 +383,4 @@ exports.useNetwork = useNetwork;

exports.useRaf = useRaf;
exports.useStorage = useStorage;
exports.useStoragePlain = useStoragePlain;
exports.useTimeout = useTimeout;

@@ -385,0 +387,0 @@ exports.useTimeoutFn = useTimeoutFn;

{
"name": "@vueuse/core",
"version": "2.0.0-alpha.11",
"version": "2.0.0-alpha.12",
"description": "Collection of essential Vue Composition API",

@@ -5,0 +5,0 @@ "main": "dist/main/index.js",

@@ -19,6 +19,12 @@ <p align="center">

## 🚀 Features
- 0 dependencies ⚡ No worry about your bundle size
- Fully tree shakable 🌴 Only take what you want
- Seamless migration 🕶 Use it now! Work for **both** Vue 3.x and 2.x
- Browser compatible 🌐 No need to setup build tools
- Intractive demos 🎪 [Check our Storybook!](https://vueuse.netlify.com)
## 📦 Install
We supports both Vue 3.x and Vue 2.x, you can seamlessly upgrade it when you migrate from Vue 2.x to 3.x.
### for Vue 3.x ([vue-next](https://github.com/vuejs/vue-next))

@@ -58,4 +64,4 @@

- useIntervalFn
- useLocalStorage
- useLocalStoragePlain
- useStorage
- useStoragePlain
- useNow

@@ -62,0 +68,0 @@ - useRaf

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