From 2019fe390085795883eff253e7b865a0fb133c4d Mon Sep 17 00:00:00 2001 From: Ed Moore Date: Fri, 3 Jun 2022 11:05:48 +0800 Subject: [PATCH] Use env var to specify nodes scratch folder #3 --- README.md | 10 ++++++++++ src/index.ts | 4 ++-- tsconfig.json | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d1929a7..612e1c6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # universal-localstorage + localstorage that works in node and the browser [![Build Status](https://img.shields.io/codeship/3bfffde0-1184-0133-460e-76104088809d.svg)](https://codeship.com/projects/92304) @@ -10,8 +11,17 @@ On node it will use [node-localstorage](https://www.npmjs.com/package/node-local On web if localstorage is available it will use the browsers version of localstorage. If the browser doesn't have localstorage it will use [Remy Sharp's pollyfill](https://gist.github.com/remy/350433) +### Change node's folder + +By default universal-localstorage will use `./uls-scratch` as the storage folder in node. +To change the folder, set the `ULS_FOLDER` to a specified folder + +```shell +ULS_FOLDER=./my_scratch_folder +``` ## Testing + ```shell npm test ``` diff --git a/src/index.ts b/src/index.ts index b5ce26e..2f4831f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,8 @@ import Storage from './rem-localstorage' let localStorage: Storage if (typeof window === 'undefined') { - const LocalStorage = require('node-localstorage').LocalStorage - localStorage = new LocalStorage('./uls-scratch') + const { LocalStorage } = require('node-localstorage') + localStorage = new LocalStorage(process.env.ULS_FOLDER || './uls-scratch') } else if ( typeof window.localStorage === 'undefined' || typeof window.sessionStorage === 'undefined' diff --git a/tsconfig.json b/tsconfig.json index c47b883..41152fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2016", + "target": "ES5", "module": "UMD", "rootDir": "./src", "declaration": true,