Skip to content

Commit 173de76

Browse files
committed
v0.0.1
1 parent 242d21b commit 173de76

File tree

8 files changed

+42
-26
lines changed

8 files changed

+42
-26
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# vstorage
1+
# valistorage
22

33
A library for efficiently managing data in `localStorage` and `sessionStorage` using **versioning** and **migrations**.
44

55
# Installation
66

77
```bash
8-
npm install vstorage
8+
npm install valistorage
99
```
1010

1111
## Creating Storage
@@ -16,7 +16,7 @@ TypeScript allows us to describe the structure of the data we want to store usin
1616

1717

1818
```ts
19-
import { create } from 'vstorage';
19+
import { create } from 'valistorage';
2020

2121
interface CatVersion1 {
2222
name: string;
@@ -36,7 +36,7 @@ Let's look at the two required parameters that we passed:
3636

3737
## Choosing Storage
3838

39-
By default, vstorage uses `localStorage` to store data.
39+
By default, valistorage uses `localStorage` to store data.
4040
You can specify the type of storage by providing `type` parameter in `create` function, which accepts either `localStorage` or `sessionStorage`.
4141

4242
```ts
@@ -86,7 +86,7 @@ catLocalStorage.remove();
8686
Imagine that we've decided to add a `color` field to our data structure. Users who have already used the application will only have `name` and `age` stored, so the application won't be able to retrieve `color`.
8787

8888
```ts
89-
import { create } from 'vstorage';
89+
import { create } from 'valistorage';
9090

9191
interface CatVersion1 {
9292
name: string;
@@ -126,7 +126,7 @@ To ensure the best user experience, we can automatically convert their data to a
126126
Let's add migrations to our `storage`.
127127

128128
```ts
129-
import { create } from 'vstorage';
129+
import { create } from 'valistorage';
130130

131131
interface CatVersion1 {
132132
name: string;
@@ -199,7 +199,7 @@ For validating data in storage and migrations, `validate` parameter is used.
199199
Let's add validation to our previous data structure:
200200

201201
```ts
202-
import { create } from 'vstorage';
202+
import { create } from 'valistorage';
203203
import * as yup from 'yup';
204204

205205
// Define data structures
@@ -251,7 +251,7 @@ export const catLocalStorage = create<CateSchemaVersion2>({
251251
To remove all values that are stored by the library, use `removeAll` method.
252252

253253
```ts
254-
import { removeAll } from 'vstorage';
254+
import { removeAll } from 'valistorage';
255255

256256
removeAll();
257257
````
@@ -264,7 +264,7 @@ By default, if no migrations are found for the data or if the data fails validat
264264
You can change this behavior by using the `autoRemove` parameter, which allows old data to be kept until it is converted to the new format or replaced with new data.
265265

266266
```ts
267-
import { create } from 'vstorage';
267+
import { create } from 'valistorage';
268268
269269
export const catLocalStorage = create({
270270
key: 'cat',

package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"name": "vstorage",
3-
"private": true,
4-
"version": "0.0.0",
2+
"name": "valistorage",
3+
"version": "0.0.1",
54
"type": "module",
65
"scripts": {
76
"dev": "vite",
@@ -10,6 +9,23 @@
109
"test:watch": "vitest",
1110
"test": "vitest --no-watch"
1211
},
12+
"author": "Maksym Levytskyi https://github.com/gmaxlev",
13+
"license": "MIT",
14+
"description": "A library for efficiently managing data in localStorage and sessionStorage using versioning and migrations.",
15+
"keywords": [
16+
"localStorage",
17+
"sessionStorage",
18+
"storage",
19+
"data",
20+
"versioning",
21+
"migrations"
22+
],
23+
"homepage": "https://github.com/gmaxlev/valistorage",
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/gmaxlev/valistorage.git"
27+
},
28+
"bugs": "https://github.com/gmaxlev/valistorage/issues",
1329
"module": "./dist/index.js",
1430
"types": "./dist/index.d.ts",
1531
"files": [

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const DEFAULT_PREFIX = '__vstorage__'
1+
export const DEFAULT_PREFIX = '__valistorage__'

src/migrations/migrations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Migration, type Version, type VstorageData } from '../types'
1+
import { type Migration, type Version, type ValistorageData } from '../types'
22
import { warn, IS_DEV } from '../utils'
33

44
const message = `"migrations" should be an array that includes the following objects:
@@ -146,7 +146,7 @@ function execute (migrations: Migration[], current: unknown): { readonly success
146146

147147
export function migrate (
148148
migrations: unknown,
149-
current: VstorageData,
149+
current: ValistorageData,
150150
to: Version
151151
): { readonly success: false, readonly value?: undefined } | { readonly success: true, readonly value: unknown } {
152152
if (!isValidMigrations(migrations)) {

src/storage/create.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function validateOptions (options: Options): void {
4848
'You passed invalid options into "create" options. Please see docs.'
4949
)
5050
}
51-
throw new Error('[vstorage.create] Invalid Options')
51+
throw new Error('[valistorage.create] Invalid Options')
5252
}
5353

5454
if (typeof options !== 'object' || options === null) {
@@ -92,14 +92,14 @@ function validateOptions (options: Options): void {
9292
}
9393
}
9494

95-
interface Vstorage <Get, Set> {
95+
interface Valistorage <Get, Set> {
9696
get: () => Get | null
9797
set: (value: Set) => void
9898
remove: () => void
9999
}
100100

101101
/**
102-
* Creates an instance of vstorage value
102+
* Creates an instance of valistorage value
103103
*
104104
* @param options - Options
105105
* @param options.key - Key to store value
@@ -111,7 +111,7 @@ interface Vstorage <Get, Set> {
111111
* @param options.autoRemove - Remove value if it is invalid (optional)
112112
* @param options.verbose - Show warnings (optional)
113113
*/
114-
export function create<Set, Get = Set> (options: Options): Vstorage<Get, Set> {
114+
export function create<Set, Get = Set> (options: Options): Valistorage<Get, Set> {
115115
validateOptions(options)
116116

117117
const {

src/storage/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { type VstorageData } from '../types'
1+
import { type ValistorageData } from '../types'
22
import { IS_DEV, warn } from '../utils'
33

4-
function isVstorageValue (
4+
function isValistorageValue (
55
value: unknown,
66
verbose: boolean
7-
): value is VstorageData {
7+
): value is ValistorageData {
88
const isValid =
99
typeof value === 'object' &&
1010
value !== null &&
@@ -21,10 +21,10 @@ function isVstorageValue (
2121
return isValid
2222
}
2323

24-
export function unpack (value: string, verbose: boolean): VstorageData | null {
24+
export function unpack (value: string, verbose: boolean): ValistorageData | null {
2525
try {
2626
const parsed = JSON.parse(value) as unknown
27-
if (!isVstorageValue(parsed, verbose)) {
27+
if (!isValistorageValue(parsed, verbose)) {
2828
return null
2929
}
3030
return parsed

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type Version = number
22

3-
export interface VstorageData {
3+
export interface ValistorageData {
44
version: Version
55
value: unknown
66
}

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function warn (message: string): void {
2-
console.warn(`[vstorage]\n\n${message}`)
2+
console.warn(`[valistorage]\n\n${message}`)
33
}
44

55
export const IS_DEV = process.env.NODE_ENV !== 'DEVELOPMENT'

0 commit comments

Comments
 (0)