Server IP : 185.86.78.101 / Your IP : 216.73.216.124 Web Server : Apache System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/wwwroot/mifepriston.org/node_modules/yeoman-generator/lib/util/ |
Upload File : |
'use strict'; const assert = require('assert'); const _ = require('lodash'); /** * Storage instances handle a json file where Generator authors can store data. * * The `Generator` class instantiate the storage named `config` by default. * * @constructor * @param {String} [name] The name of the new storage (this is a namespace) * @param {mem-fs-editor} fs A mem-fs editor instance * @param {String} configPath The filepath used as a storage. * @param {Boolean} lodashPath Set true to treat name as a lodash path. * * @example * class extend Generator { * writing: function() { * this.config.set('coffeescript', false); * } * } */ class Storage { constructor(name, fs, configPath, lodashPath = false) { if (name !== undefined && typeof name !== 'string') { configPath = fs; fs = name; name = undefined; } assert(configPath, 'A config filepath is required to create a storage'); this.path = configPath; this.name = name; this.fs = fs; this.existed = Object.keys(this._store).length > 0; this.indent = 2; this.lodashPath = lodashPath; } /** * Return the current store as JSON object * @return {Object} the store content * @private */ get _store() { const store = this.fs.readJSON(this.path, {}); if (!this.name) { return store || {}; } return (this.lodashPath ? _.get(store, this.name) : store[this.name]) || {}; } /** * Persist a configuration to disk * @param {Object} val - current configuration values * @private */ _persist(val) { let fullStore; if (this.name) { fullStore = this.fs.readJSON(this.path, {}); if (this.lodashPath) { _.set(fullStore, this.name, val); } else { fullStore[this.name] = val; } } else { fullStore = val; } this.fs.writeJSON(this.path, fullStore, null, this.indent); } /** * Save a new object of values */ save() { this._persist(this._store); } /** * Get a stored value * @param {String} key The key under which the value is stored. * @return {*} The stored value. Any JSON valid type could be returned */ get(key) { return this._store[key]; } /** * Get a stored value from a lodash path * @param {String} path The path under which the value is stored. * @return {*} The stored value. Any JSON valid type could be returned */ getPath(path) { return _.get(this._store, path); } /** * Get all the stored values * @return {Object} key-value object */ getAll() { return _.cloneDeep(this._store); } /** * Assign a key to a value and schedule a save. * @param {String} key The key under which the value is stored * @param {*} val Any valid JSON type value (String, Number, Array, Object). * @return {*} val Whatever was passed in as val. */ set(key, val) { assert(!_.isFunction(val), "Storage value can't be a function"); const store = this._store; if (_.isObject(key)) { val = _.assignIn(store, key); } else { store[key] = val; } this._persist(store); return val; } /** * Assign a lodash path to a value and schedule a save. * @param {String} path The key under which the value is stored * @param {*} val Any valid JSON type value (String, Number, Array, Object). * @return {*} val Whatever was passed in as val. */ setPath(path, val) { assert(!_.isFunction(val), "Storage value can't be a function"); const store = this._store; _.set(store, path, val); this._persist(store); return val; } /** * Delete a key from the store and schedule a save. * @param {String} key The key under which the value is stored. */ delete(key) { const store = this._store; delete store[key]; this._persist(store); } /** * Setup the store with defaults value and schedule a save. * If keys already exist, the initial value is kept. * @param {Object} defaults Key-value object to store. * @return {*} val Returns the merged options. */ defaults(defaults) { assert(_.isObject(defaults), 'Storage `defaults` method only accept objects'); const val = _.defaults(this.getAll(), defaults); this.set(val); return val; } } module.exports = Storage;