daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Nov 8th, 2018 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Settings = require('./Settings').shared;
  2. // or
  3. const Settings = require('./Settings')('~/my-app-settings.json');
  4.  
  5. const { prompt } = require('inquirer');
  6.  
  7. (async () => {
  8.     const wait = delay => new Promise(resolve => setTimeout(() => resolve(), delay));
  9.  
  10.     try {
  11.         const answers = await prompt([{
  12.             name: 'firstName',
  13.             message: 'What\'s your name?',
  14.             prefix: 'i.',
  15.             default: 'John',
  16.             filter: input => input.trim(),
  17.             validate: input => input.length > 0
  18.         }, {
  19.             name: 'lastName',
  20.             message: 'And your last name?',
  21.             prefix: 'ii.',
  22.             default: 'Doe',
  23.             filter: input => input.trim(),
  24.             validate: input => input.length > 0
  25.         }, {
  26.             name: 'bday',
  27.             message: 'When are you born?',
  28.             prefix: 'iii.',
  29.             default: new Date().toLocaleString(),
  30.             when: a => a.firstName && a.lastName
  31.         }]);
  32.  
  33.         const user = {};
  34.  
  35.         user.first = answers.firstName;
  36.         user.last = answers.lastName;
  37.         user.bday = new Date(answers.bday);
  38.         user.age = Math.abs(new Date().getFullYear() - new Date(answers.bday).getFullYear());
  39.  
  40.         Settings.set('user', user);
  41.  
  42.         await wait(500);
  43.  
  44.         console.log({
  45.             exists: Settings.has('user'),
  46.             content: Settings.get('user')
  47.         });
  48.  
  49.         await wait(500);
  50.  
  51.         Settings.delete('user');
  52.  
  53.         console.log({
  54.             exists: Settings.has('user'),
  55.             content: Settings.get('user')
  56.         });
  57.     } catch (error) {
  58.         throw error;
  59.     }
  60. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top