How to use the node-localstorage.JSONStorage function in node-localstorage

To help you get started, we’ve selected a few node-localstorage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kilian / messenger-demo-viewer / index.js View on Github external
const electron = require('electron');
const https = require('https');

const { app, BrowserWindow, globalShortcut: gsc, Menu: menu, shell } = electron;
const APPVERSION = require('./package.json').version;
const JSONStorage = require('node-localstorage').JSONStorage;
const compareVersions = require('compare-versions');

if (process.env.NODE_ENV === 'development') {
  // eslint-disable-next-line global-require
  require('electron-debug')({ showDevTools: true });
}

global.nodeStorage = new JSONStorage(app.getPath('userData') + (process.env.NODE_ENV === 'development' ? '/dev' : ''));

let mainWindow = null;
app.on('window-all-closed', () => {
  app.quit();
});

app.on('ready', () => {
  let windowState = {};
  try {
    windowState = global.nodeStorage.getItem('window-state') || {};
  } catch (err) {
    console.log('empty window state file, creating new one.');
  }

  const windowSettings = {
    show: false,
github PhinchApp / Phinch / app / analytics.js View on Github external
import ua from 'universal-analytics';
import uuid from 'uuid';
import { remote } from 'electron';
import { JSONStorage } from 'node-localstorage';

// ref: https://kilianvalkhof.com/2018/apps/using-google-analytics-to-gather-usage-statistics-in-electron/

const nodeStorage = new JSONStorage(remote.app.getPath('userData'));
const visitorId = nodeStorage.getItem('visitorid') || uuid();
nodeStorage.setItem('visitorid', visitorId);

const visitor = ua('UA-50346302-2', visitorId);

export function trackEvent(category, action, label, value) {
  visitor.event({
    ec: category,
    ea: action,
    el: label,
    ev: value,
  }).send();
}

export function pageView(location) {
  visitor.pageview(location).send();
github EtherWorld / EtherWorld / src / shared / storage.js View on Github external
if (global.window) {
  var ls = require('local-storage');
} else {
  var LocalStorage = require('node-localstorage').JSONStorage;

  // Normalise the method names so they're consistent.
  LocalStorage.prototype.set = LocalStorage.prototype.setItem;
  LocalStorage.prototype.get = LocalStorage.prototype.getItem;
  LocalStorage.prototype.remove = LocalStorage.prototype.removeItem;

  var path = require('path').normalize(__dirname + '../../../db');

  ls = new LocalStorage(path);
}


module.exports = ls;
github Kilian / fromscratch / app / main.dev.js View on Github external
const getDataLocation = () => {
    let location = `${process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME']}/.fromscratch${
      isDev ? '/dev' : ''
    }`;

    if (typeof argv.portable !== 'undefined') {
      location = argv.portable !== '' ? argv.portable : `${process.cwd()}/userdata`;
      app.setPath('userData', location);
    }

    return location;
  };

  const storageLocation = getDataLocation();

  global.nodeStorage = new JSONStorage(storageLocation);

  global.handleContent = {
    filename: `${storageLocation}/content.txt`,
    write(content) {
      fs.writeFileSync(this.filename, content, 'utf8');
    },
    read() {
      return fs.existsSync(this.filename) ? fs.readFileSync(this.filename, 'utf8') : false;
    },
  };

  const installExtensions = () => {
    if (isDev) {
      const installer = require('electron-devtools-installer'); // eslint-disable-line global-require
      const extensions = ['REACT_DEVELOPER_TOOLS'];
      const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
github fresk-nc / VOX / main.js View on Github external
app.on('ready', function() {
    if (isDev) {
        installExtensions();
    }

    const storage = new JSONStorage(isDev ? config.devUserData : app.getPath('userData'));
    const settings = storage.getItem('reduxPersist:settings');

    let width = config.maxSize.width;
    let height = config.maxSize.height;

    if (settings && settings.minimize) {
        width = config.minSize.width;
        height = config.minSize.height;
    }

    mainWindow = new BrowserWindow({
        width: width,
        height: height,
        show: false,
        resizable: isDev,
        backgroundColor: config.backgroundColor,

node-localstorage

A drop-in substitute for the browser native localStorage API that runs on node.js.

MIT
Latest version published 12 months ago

Package Health Score

72 / 100
Full package analysis