How to use node-localstorage - 10 common examples

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 lzwme / ajax-data-model / test / helpers / _helper.js View on Github external
html: undefined,
    src: fs.readFileSync('./node_modules/jquery/dist/jquery.js', 'utf-8')
});

global.fs = fs;
global.chai = chai;
// global.adm = adm;

// 使用 chai.expect 断言
chai.expect();
global.expect = chai.expect;

// localStorage
const LocalStorage = require('node-localstorage').LocalStorage;

global.localStorage = new LocalStorage('./test/localStorageTemp');
before(function (next) {
    global.adm = require('../../src/adm.jquery.js');
    global.window = document.defaultView;
    global.localStorage = global.localStorage || new LocalStorage('./test/localStorageTemp');
    global.window.localStorage = global.localStorage;

    next();
});

// import test from 'ava';
// global.test = test;

// global.document = jsdom('<p></p>');
// global.window = document.defaultView;
// global.navigator = window.navigator;
github inkandswitch / capstone / src / apps / make-bot / make-bot.ts View on Github external
console.log(
    "Usage: ./make-bot --workspace workspaceId --id botId bot-code.js",
  )
  process.exit(0)
}

const code = fs.readFileSync(fileName, "utf-8")

import { LocalStorage } from "node-localstorage"

interface Global {
  localStorage: LocalStorage
}
declare var global: Global

global.localStorage = new LocalStorage("./localstorage")

const raf = require("random-access-file")
import { Doc } from "automerge/frontend"
import { last, once } from "lodash"

import * as Link from "../../data/Link"
import Store from "../../data/Store"
import StoreBackend from "../../data/StoreBackend"

import CloudClient from "discovery-cloud/Client"
import { Hypermerge, FrontendManager } from "hypermerge"

import "./Bot" // we have local bot implementation since the Capstone one uses css imports
import * as Board from "../../components/Board"
import * as DataImport from "../../components/DataImport"
import * as Workspace from "../../components/Workspace"
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 JaredHawkins / TweetGeoViz / server / public / js / models / appModel.js View on Github external
/*global module, require*/

var tgv = tgv || {};

// Node.js detection. For testing
if (typeof module !== 'undefined' && module.exports) {
  tgv.utils = require('../utils.js');
  var LocalStorage = require('node-localstorage').LocalStorage,
      localStorage = new LocalStorage('./nodeLocalStorage');
}

(function(utils) {

  var AppModel = function(options) {
    this._init = this._init.bind(this);
    this.getClickRadius = this.getClickRadius.bind(this);
    this.getMapClickEnabled = this.getMapClickEnabled.bind(this);
    this.setClickRadius = this.setClickRadius.bind(this);
    this.setMapClickEnabled = this.setMapClickEnabled.bind(this);
    this.getClickRadiusMeters = this.getClickRadiusMeters.bind(this);

    // get default values from localStorage if they are available
    var defaults = {
      clickRadius: 250,
      mapClickEnabled: true
github swaponline / swap.core / simple / src / config / getConfig.js View on Github external
swapAuth: {
      ...common.swapAuth,
      ...config.swapAuth,
      ...custom.swapAuth,
    },

    swapRoom: {
      ...common.swapRoom,
      ...config.swapRoom,
      ...custom.swapRoom,
    },
  }

  setupLocalStorage()

  const storage = new LocalStorage(config.storageDir)

  const web3    = eth[config.network]().core
  const bitcoin = btc[config.network]().core

  const tokens = (config.ERC20TOKENS || [])
    .map(_token => ({ network: config.network, ..._token }))
    .filter(_token => _token.network === config.network)

  return {
    network: config.network,
    constants,
    env: {
      web3,
      bitcoin,
      // bcash,
      Ipfs,
github kndt84 / passport-cognito / lib / cognito / CognitoUser.js View on Github external
cacheDeviceKeyAndPassword() {
    const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${this.username}`;
    const deviceKeyKey = `${keyPrefix}.deviceKey`;
    const randomPasswordKey = `${keyPrefix}.randomPasswordKey`;
    const deviceGroupKeyKey = `${keyPrefix}.deviceGroupKey`;

//    const storage = window.localStorage;
    const storage = new LocalStorage('/tmp/storage');

    storage.setItem(deviceKeyKey, this.deviceKey);
    storage.setItem(randomPasswordKey, this.randomPassword);
    storage.setItem(deviceGroupKeyKey, this.deviceGroupKey);
  }
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 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;

node-localstorage

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

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis