1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-27 07:45:08 +02:00

less underscore

This commit is contained in:
antelle 2019-09-17 22:17:40 +02:00
parent 94660d9e71
commit 89ccb99395
30 changed files with 76 additions and 88 deletions

View File

@ -450,7 +450,7 @@ AutoTypeRunner.prototype.emitNext = function(err) {
if (this.emitterState.opIx >= this.emitterState.ops.length) { if (this.emitterState.opIx >= this.emitterState.ops.length) {
const state = this.emitterState.stack.pop(); const state = this.emitterState.stack.pop();
if (state) { if (state) {
_.extend(this.emitterState, { ops: state.ops, opIx: state.opIx, mod: state.mod }); Object.assign(this.emitterState, { ops: state.ops, opIx: state.opIx, mod: state.mod });
this.emitNext(); this.emitNext();
} else { } else {
this.resetEmitterMod({}); this.resetEmitterMod({});
@ -470,7 +470,7 @@ AutoTypeRunner.prototype.emitNext = function(err) {
opIx: this.emitterState.opIx + 1, opIx: this.emitterState.opIx + 1,
mod: _.clone(this.emitterState.mod) mod: _.clone(this.emitterState.mod)
}); });
_.extend(this.emitterState, { Object.assign(this.emitterState, {
ops: op.value, ops: op.value,
opIx: 0, opIx: 0,
mod: _.clone(this.emitterState.activeMod) mod: _.clone(this.emitterState.activeMod)

View File

@ -129,7 +129,7 @@ const GeneratorPresets = {
const setting = this.getOrCreateSetting(); const setting = this.getOrCreateSetting();
const preset = setting.user.filter(p => p.name === name)[0]; const preset = setting.user.filter(p => p.name === name)[0];
if (preset) { if (preset) {
_.extend(preset, props); Object.assign(preset, props);
this.save(setting); this.save(setting);
} }
}, },

View File

@ -18,7 +18,7 @@ const Transport = {
fs.unlinkSync(tmpFile); fs.unlinkSync(tmpFile);
} }
} catch (e) { } catch (e) {
fs.unlink(tmpFile, _.noop); fs.unlink(tmpFile, () => {});
} }
} }
} }
@ -81,7 +81,7 @@ const Transport = {
.on('error', e => { .on('error', e => {
logger.error('Cannot GET ' + config.url, e); logger.error('Cannot GET ' + config.url, e);
if (tmpFile) { if (tmpFile) {
fs.unlink(tmpFile, _.noop); fs.unlink(tmpFile, () => {});
} }
config.error(e); config.error(e);
}); });

View File

@ -267,7 +267,7 @@ const Launcher = {
return; return;
} }
const encryptConfig = _.extend({}, this.config, { const encryptConfig = Object.assign({}, this.config, {
username: fileId, username: fileId,
password: password.getText() password: password.getText()
}); });
@ -283,7 +283,7 @@ const Launcher = {
return callback(); return callback();
} }
const decryptConfig = _.extend({}, this.config, { const decryptConfig = Object.assign({}, this.config, {
username: fileId, username: fileId,
token token
}); });

View File

@ -84,7 +84,7 @@ const Launcher = {
this.req('fs').exists(path, callback); this.req('fs').exists(path, callback);
}, },
deleteFile(path, callback) { deleteFile(path, callback) {
this.req('fs').unlink(path, callback || _.noop); this.req('fs').unlink(path, callback || (() => {}));
}, },
statFile(path, callback) { statFile(path, callback) {
this.req('fs').stat(path, (err, stats) => callback(stats, err)); this.req('fs').stat(path, (err, stats) => callback(stats, err));

View File

@ -47,11 +47,11 @@ const SettingsManager = {
}, },
setTheme(theme) { setTheme(theme) {
_.forEach(document.body.classList, cls => { for (const cls of document.body.classList) {
if (/^th\-/.test(cls)) { if (/^th-/.test(cls)) {
document.body.classList.remove(cls); document.body.classList.remove(cls);
} }
}); }
document.body.classList.add(this.getThemeClass(theme)); document.body.classList.add(this.getThemeClass(theme));
const metaThemeColor = document.head.querySelector('meta[name=theme-color]'); const metaThemeColor = document.head.querySelector('meta[name=theme-color]');
if (metaThemeColor) { if (metaThemeColor) {
@ -83,7 +83,7 @@ const SettingsManager = {
if (!this.neutralLocale) { if (!this.neutralLocale) {
this.neutralLocale = _.clone(Locale); this.neutralLocale = _.clone(Locale);
} }
_.extend(Locale, this.neutralLocale, localeValues); Object.assign(Locale, this.neutralLocale, localeValues);
this.activeLocale = loc; this.activeLocale = loc;
Events.emit('set-locale', loc); Events.emit('set-locale', loc);
}, },

View File

@ -67,7 +67,7 @@ const Alerts = {
info(config) { info(config) {
this.alert( this.alert(
_.extend( Object.assign(
{ {
header: '', header: '',
body: '', body: '',
@ -84,7 +84,7 @@ const Alerts = {
error(config) { error(config) {
this.alert( this.alert(
_.extend( Object.assign(
{ {
header: '', header: '',
body: '', body: '',
@ -101,7 +101,7 @@ const Alerts = {
yesno(config) { yesno(config) {
this.alert( this.alert(
_.extend( Object.assign(
{ {
header: '', header: '',
body: '', body: '',

View File

@ -48,7 +48,9 @@ class AppModel {
prepare() { prepare() {
AutoType.init(this); AutoType.init(this);
_.forEach(Storage, prv => prv.init()); for (const prv of Object.values(Storage)) {
prv.init();
}
} }
loadConfig(configLocation) { loadConfig(configLocation) {
@ -181,12 +183,12 @@ class AppModel {
tagsHash[tag.toLowerCase()] = true; tagsHash[tag.toLowerCase()] = true;
}); });
file.forEachEntry({}, entry => { file.forEachEntry({}, entry => {
_.forEach(entry.tags, tag => { for (const tag of entry.tags) {
if (!tagsHash[tag.toLowerCase()]) { if (!tagsHash[tag.toLowerCase()]) {
tagsHash[tag.toLowerCase()] = true; tagsHash[tag.toLowerCase()] = true;
this.tags.push(tag); this.tags.push(tag);
} }
}); }
}); });
this.tags.sort(); this.tags.sort();
} }
@ -282,7 +284,7 @@ class AppModel {
} }
addFilter(filter) { addFilter(filter) {
this.setFilter(_.extend(this.filter, filter)); this.setFilter(Object.assign(this.filter, filter));
} }
setSort(sort) { setSort(sort) {
@ -1133,7 +1135,7 @@ class AppModel {
this.setFileBackup(file.id, backup); this.setFileBackup(file.id, backup);
} }
if (needBackup) { if (needBackup) {
this.backupFile(file, data, _.noop); this.backupFile(file, data, () => {});
} }
} }

View File

@ -97,11 +97,11 @@ const EntryModel = Backbone.Model.extend({
_buildSearchText() { _buildSearchText() {
let text = ''; let text = '';
_.forEach(this.entry.fields, value => { for (const value of Object.values(this.entry.fields)) {
if (typeof value === 'string') { if (typeof value === 'string') {
text += value.toLowerCase() + '\n'; text += value.toLowerCase() + '\n';
} }
}); }
this.entry.tags.forEach(tag => { this.entry.tags.forEach(tag => {
text += tag.toLowerCase() + '\n'; text += tag.toLowerCase() + '\n';
}); });
@ -164,18 +164,14 @@ const EntryModel = Backbone.Model.extend({
_attachmentsToModel(binaries) { _attachmentsToModel(binaries) {
const att = []; const att = [];
_.forEach( for (let [title, data] of Object.entries(binaries)) {
binaries, if (data && data.ref) {
(data, title) => { data = data.value;
if (data && data.ref) { }
data = data.value; if (data) {
} att.push(AttachmentModel.fromAttachment({ data, title }));
if (data) { }
att.push(AttachmentModel.fromAttachment({ data, title })); }
}
},
this
);
return att; return att;
}, },

View File

@ -137,7 +137,7 @@ class FileModel extends Model {
} }
setOpenFile(props) { setOpenFile(props) {
_.extend(props, { Object.assign(props, {
active: true, active: true,
oldKeyFileName: this.keyFileName, oldKeyFileName: this.keyFileName,
oldPasswordLength: props.passwordLength, oldPasswordLength: props.passwordLength,

View File

@ -11,7 +11,7 @@ const KdbxIcons = kdbxweb.Consts.Icons;
const DefaultAutoTypeSequence = '{USERNAME}{TAB}{PASSWORD}{ENTER}'; const DefaultAutoTypeSequence = '{USERNAME}{TAB}{PASSWORD}{ENTER}';
const GroupModel = MenuItemModel.extend({ const GroupModel = MenuItemModel.extend({
defaults: _.extend({}, MenuItemModel.prototype.defaults, { defaults: Object.assign({}, MenuItemModel.prototype.defaults, {
iconId: 0, iconId: 0,
entries: null, entries: null,
filterKey: 'group', filterKey: 'group',

View File

@ -2,7 +2,7 @@ import { GroupCollection } from 'collections/group-collection';
import { MenuSectionModel } from 'models/menu/menu-section-model'; import { MenuSectionModel } from 'models/menu/menu-section-model';
const GroupsMenuModel = MenuSectionModel.extend({ const GroupsMenuModel = MenuSectionModel.extend({
defaults: _.extend({}, MenuSectionModel.prototype.defaults, { defaults: Object.assign({}, MenuSectionModel.prototype.defaults, {
scrollable: true, scrollable: true,
grow: true grow: true
}), }),

View File

@ -6,11 +6,11 @@ class UpdateModel extends Model {
return SettingsStore.load('update-info').then(data => { return SettingsStore.load('update-info').then(data => {
if (data) { if (data) {
try { try {
_.each(data, (val, key) => { for (const [key, val] of Object.entries(data)) {
if (/Date$/.test(key)) { if (/Date$/.test(key)) {
data[key] = val ? new Date(val) : null; data[key] = val ? new Date(val) : null;
} }
}); }
this.set(data, { silent: true }); this.set(data, { silent: true });
} catch (e) { } catch (e) {
/* failed to load model */ /* failed to load model */

View File

@ -30,7 +30,7 @@ const PluginStatus = {
}; };
const Plugin = Backbone.Model.extend( const Plugin = Backbone.Model.extend(
_.extend({}, PluginStatus, { Object.assign({}, PluginStatus, {
idAttribute: 'name', idAttribute: 'name',
defaults: { defaults: {
@ -617,7 +617,7 @@ const Plugin = Backbone.Model.extend(
}) })
); );
_.extend(Plugin, PluginStatus); Object.assign(Plugin, PluginStatus);
Plugin.loadFromUrl = function(url, expectedManifest) { Plugin.loadFromUrl = function(url, expectedManifest) {
if (url[url.length - 1] !== '/') { if (url[url.length - 1] !== '/') {

View File

@ -370,9 +370,9 @@ const StorageWebDav = StorageBase.extend({
); );
} }
if (config.headers) { if (config.headers) {
_.forEach(config.headers, (value, header) => { for (const [header, value] of Object.entries(config.headers)) {
xhr.setRequestHeader(header, value); xhr.setRequestHeader(header, value);
}); }
} }
if (['GET', 'HEAD'].indexOf(config.method) >= 0) { if (['GET', 'HEAD'].indexOf(config.method) >= 0) {
xhr.setRequestHeader('Cache-Control', 'no-cache'); xhr.setRequestHeader('Cache-Control', 'no-cache');

View File

@ -21,7 +21,7 @@ const ThirdPartyStorage = {
const Storage = BuiltInStorage; const Storage = BuiltInStorage;
if (!Launcher || Launcher.thirdPartyStoragesSupported) { if (!Launcher || Launcher.thirdPartyStoragesSupported) {
_.extend(Storage, ThirdPartyStorage); Object.assign(Storage, ThirdPartyStorage);
} }
export { Storage }; export { Storage };

View File

@ -6,7 +6,7 @@ const IoBrowserCache = function(config) {
this.logger = config.logger; this.logger = config.logger;
}; };
_.extend(IoBrowserCache.prototype, { Object.assign(IoBrowserCache.prototype, {
initDb(callback) { initDb(callback) {
if (this.db) { if (this.db) {
return callback && callback(); return callback && callback();

View File

@ -6,7 +6,7 @@ const IoFileCache = function(config) {
this.logger = config.logger; this.logger = config.logger;
}; };
_.extend(IoFileCache.prototype, { Object.assign(IoFileCache.prototype, {
initFs(callback) { initFs(callback) {
if (this.basePath) { if (this.basePath) {
return callback(); return callback();

View File

@ -10,7 +10,7 @@ const MaxRequestRetries = 3;
const StorageBase = function() {}; const StorageBase = function() {};
_.extend(StorageBase.prototype, { Object.assign(StorageBase.prototype, {
name: null, name: null,
icon: null, icon: null,
iconSvg: null, iconSvg: null,
@ -97,9 +97,9 @@ _.extend(StorageBase.prototype, {
if (this._oauthToken && !config.skipAuth) { if (this._oauthToken && !config.skipAuth) {
xhr.setRequestHeader('Authorization', 'Bearer ' + this._oauthToken.accessToken); xhr.setRequestHeader('Authorization', 'Bearer ' + this._oauthToken.accessToken);
} }
_.forEach(config.headers, (value, key) => { for (const [key, value] of Object.entries(config.headers)) {
xhr.setRequestHeader(key, value); xhr.setRequestHeader(key, value);
}); }
let data = config.data; let data = config.data;
if (data instanceof ArrayBuffer) { if (data instanceof ArrayBuffer) {
data = new Uint8Array(data); data = new Uint8Array(data);

View File

@ -105,13 +105,13 @@ Color.getNearest = function(colorStr) {
} }
let selected = null, let selected = null,
minDistance = Number.MAX_VALUE; minDistance = Number.MAX_VALUE;
_.forEach(KnownColors, (col, name) => { for (const [name, col] of Object.entries(KnownColors)) {
const distance = color.distanceTo(col); const distance = color.distanceTo(col);
if (distance < minDistance) { if (distance < minDistance) {
minDistance = distance; minDistance = distance;
selected = name; selected = name;
} }
}); }
return selected; return selected;
}; };
@ -119,9 +119,9 @@ Color.getKnownBgColor = function(knownColor) {
return Colors.BgColors[knownColor] ? '#' + Colors.BgColors[knownColor] : undefined; return Colors.BgColors[knownColor] ? '#' + Colors.BgColors[knownColor] : undefined;
}; };
_.forEach(Colors.ColorsValues, (val, name) => { for (const [name, val] of Object.entries(Colors.ColorsValues)) {
KnownColors[name] = new Color(val); KnownColors[name] = new Color(val);
}); }
Color.black = new Color('#000'); Color.black = new Color('#000');

View File

@ -102,11 +102,11 @@ const PasswordGenerator = {
password.forEachChar(ch => { password.forEachChar(ch => {
length++; length++;
ch = String.fromCharCode(ch); ch = String.fromCharCode(ch);
_.forEach(charRanges, (chars, range) => { for (const [range, chars] of Object.entries(charRanges)) {
if (chars.indexOf(ch) >= 0) { if (chars.indexOf(ch) >= 0) {
opts[range] = true; opts[range] = true;
} }
}); }
}); });
} }
opts.length = length; opts.length = length;

View File

@ -183,7 +183,7 @@ Tip.hideTip = function(el) {
Tip.updateTip = function(el, props) { Tip.updateTip = function(el, props) {
if (el._tip) { if (el._tip) {
el._tip.hide(); el._tip.hide();
_.extend( Object.assign(
el._tip, el._tip,
_.pick(props, ['title', 'placement', 'fast', 'showTimeout', 'hideTimeout']) _.pick(props, ['title', 'placement', 'fast', 'showTimeout', 'hideTimeout'])
); );

View File

@ -200,15 +200,9 @@ class DetailsHistoryView extends View {
value: this.record.expires ? DateFormat.dtStr(this.record.expires) : '' value: this.record.expires ? DateFormat.dtStr(this.record.expires) : ''
}) })
); );
_.forEach( for (const [field, value] of Object.entries(this.record.fields)) {
this.record.fields, this.fieldViews.push(new FieldViewReadOnly({ name: '$' + field, title: field, value }));
(value, field) => { }
this.fieldViews.push(
new FieldViewReadOnly({ name: '$' + field, title: field, value })
);
},
this
);
if (this.record.attachments.length) { if (this.record.attachments.length) {
this.fieldViews.push( this.fieldViews.push(
new FieldViewReadOnly({ new FieldViewReadOnly({

View File

@ -268,7 +268,7 @@ class DetailsView extends View {
} }
}) })
); );
_.forEach(model.fields, (value, field) => { for (const field of Object.keys(model.fields)) {
if (field === 'otp' && this.model.otpGenerator) { if (field === 'otp' && this.model.otpGenerator) {
this.fieldViews.push( this.fieldViews.push(
new FieldViewOtp({ new FieldViewOtp({
@ -291,7 +291,7 @@ class DetailsView extends View {
}) })
); );
} }
}); }
const hideEmptyFields = AppSettingsModel.hideEmptyFields; const hideEmptyFields = AppSettingsModel.hideEmptyFields;
@ -466,11 +466,11 @@ class DetailsView extends View {
.find('.details__colors-popup > .details__colors-popup-item') .find('.details__colors-popup > .details__colors-popup-item')
.removeClass('details__colors-popup-item--active'); .removeClass('details__colors-popup-item--active');
const colorEl = this.$el.find('.details__header-color')[0]; const colorEl = this.$el.find('.details__header-color')[0];
_.forEach(colorEl.classList, cls => { for (const cls of colorEl.classList) {
if (cls.indexOf('color') > 0 && cls.lastIndexOf('details', 0) !== 0) { if (cls.indexOf('color') > 0 && cls.lastIndexOf('details', 0) !== 0) {
colorEl.classList.remove(cls); colorEl.classList.remove(cls);
} }
}); }
if (color) { if (color) {
this.$el this.$el
.find('.details__colors-popup > .' + color + '-color') .find('.details__colors-popup > .' + color + '-color')
@ -778,17 +778,13 @@ class DetailsView extends View {
} }
addAttachedFiles(files) { addAttachedFiles(files) {
_.forEach( for (const file of files) {
files, const reader = new FileReader();
function(file) { reader.onload = () => {
const reader = new FileReader(); this.addAttachment(file.name, reader.result);
reader.onload = () => { };
this.addAttachment(file.name, reader.result); reader.readAsArrayBuffer(file);
}; }
reader.readAsArrayBuffer(file);
},
this
);
} }
addAttachment(name, data) { addAttachment(name, data) {
@ -989,7 +985,7 @@ class DetailsView extends View {
if (AutoType.enabled) { if (AutoType.enabled) {
options.push({ value: 'det-auto-type', icon: 'keyboard-o', text: Locale.detAutoType }); options.push({ value: 'det-auto-type', icon: 'keyboard-o', text: Locale.detAutoType });
} }
Events.emit('show-context-menu', _.extend(e, { options })); Events.emit('show-context-menu', Object.assign(e, { options }));
} }
contextMenuSelect(e) { contextMenuSelect(e) {

View File

@ -36,7 +36,7 @@ class FieldViewCustom extends FieldViewText {
endEdit(newVal, extra) { endEdit(newVal, extra) {
this.$el.removeClass('details__field--can-edit-title'); this.$el.removeClass('details__field--can-edit-title');
extra = _.extend({}, extra); extra = Object.assign({}, extra);
if (this.model.titleChanged || this.model.newField) { if (this.model.titleChanged || this.model.newField) {
extra.newField = this.model.title; extra.newField = this.model.title;
} }

View File

@ -150,7 +150,7 @@ class FieldView extends View {
if (newVal !== undefined && (!textEqual || !protectedEqual || nameChanged)) { if (newVal !== undefined && (!textEqual || !protectedEqual || nameChanged)) {
arg = { val: newVal, field: this.model.name }; arg = { val: newVal, field: this.model.name };
if (extra) { if (extra) {
_.extend(arg, extra); Object.assign(arg, extra);
} }
} else if (extra) { } else if (extra) {
arg = extra; arg = extra;

View File

@ -94,7 +94,7 @@ class GeneratorView extends View {
(!this.model.password.isProtected || this.model.password.byteLength) (!this.model.password.isProtected || this.model.password.byteLength)
) { ) {
const derivedPreset = { name: 'Derived', title: Locale.genPresetDerived }; const derivedPreset = { name: 'Derived', title: Locale.genPresetDerived };
_.extend(derivedPreset, PasswordGenerator.deriveOpts(this.model.password)); Object.assign(derivedPreset, PasswordGenerator.deriveOpts(this.model.password));
this.presets.splice(0, 0, derivedPreset); this.presets.splice(0, 0, derivedPreset);
this.preset = 'Derived'; this.preset = 'Derived';
} else { } else {

View File

@ -115,7 +115,7 @@ class ListSearchView extends View {
title: true title: true
}; };
if (this.model.advancedSearch) { if (this.model.advancedSearch) {
this.advancedSearch = _.extend({}, this.model.advancedSearch); this.advancedSearch = Object.assign({}, this.model.advancedSearch);
} }
this.setLocale(); this.setLocale();
this.onKey(Keys.DOM_VK_F, this.findKeyPress, KeyHandler.SHORTCUT_ACTION); this.onKey(Keys.DOM_VK_F, this.findKeyPress, KeyHandler.SHORTCUT_ACTION);

View File

@ -801,7 +801,7 @@ class OpenView extends View {
if (this.views.openConfig) { if (this.views.openConfig) {
this.views.openConfig.remove(); this.views.openConfig.remove();
} }
const config = _.extend( const config = Object.assign(
{ {
id: storage.name, id: storage.name,
name: Locale[storage.name] || storage.name, name: Locale[storage.name] || storage.name,

View File

@ -125,7 +125,7 @@ class SettingsFileView extends View {
kdfParametersToUi(kdfParameters) { kdfParametersToUi(kdfParameters) {
return kdfParameters return kdfParameters
? _.extend({}, kdfParameters, { memory: Math.round(kdfParameters.memory / 1024) }) ? Object.assign({}, kdfParameters, { memory: Math.round(kdfParameters.memory / 1024) })
: null; : null;
} }
@ -282,7 +282,7 @@ class SettingsFileView extends View {
} else { } else {
if (!storage.list) { if (!storage.list) {
if (storage.getOpenConfig) { if (storage.getOpenConfig) {
const config = _.extend( const config = Object.assign(
{ {
id: storage.name, id: storage.name,
name: Locale[storage.name] || storage.name, name: Locale[storage.name] || storage.name,