1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-20 06:56:40 +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) {
const state = this.emitterState.stack.pop();
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();
} else {
this.resetEmitterMod({});
@ -470,7 +470,7 @@ AutoTypeRunner.prototype.emitNext = function(err) {
opIx: this.emitterState.opIx + 1,
mod: _.clone(this.emitterState.mod)
});
_.extend(this.emitterState, {
Object.assign(this.emitterState, {
ops: op.value,
opIx: 0,
mod: _.clone(this.emitterState.activeMod)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ const MaxRequestRetries = 3;
const StorageBase = function() {};
_.extend(StorageBase.prototype, {
Object.assign(StorageBase.prototype, {
name: null,
icon: null,
iconSvg: null,
@ -97,9 +97,9 @@ _.extend(StorageBase.prototype, {
if (this._oauthToken && !config.skipAuth) {
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);
});
}
let data = config.data;
if (data instanceof ArrayBuffer) {
data = new Uint8Array(data);

View File

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

View File

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

View File

@ -183,7 +183,7 @@ Tip.hideTip = function(el) {
Tip.updateTip = function(el, props) {
if (el._tip) {
el._tip.hide();
_.extend(
Object.assign(
el._tip,
_.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) : ''
})
);
_.forEach(
this.record.fields,
(value, field) => {
this.fieldViews.push(
new FieldViewReadOnly({ name: '$' + field, title: field, value })
);
},
this
);
for (const [field, value] of Object.entries(this.record.fields)) {
this.fieldViews.push(new FieldViewReadOnly({ name: '$' + field, title: field, value }));
}
if (this.record.attachments.length) {
this.fieldViews.push(
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) {
this.fieldViews.push(
new FieldViewOtp({
@ -291,7 +291,7 @@ class DetailsView extends View {
})
);
}
});
}
const hideEmptyFields = AppSettingsModel.hideEmptyFields;
@ -466,11 +466,11 @@ class DetailsView extends View {
.find('.details__colors-popup > .details__colors-popup-item')
.removeClass('details__colors-popup-item--active');
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) {
colorEl.classList.remove(cls);
}
});
}
if (color) {
this.$el
.find('.details__colors-popup > .' + color + '-color')
@ -778,17 +778,13 @@ class DetailsView extends View {
}
addAttachedFiles(files) {
_.forEach(
files,
function(file) {
const reader = new FileReader();
reader.onload = () => {
this.addAttachment(file.name, reader.result);
};
reader.readAsArrayBuffer(file);
},
this
);
for (const file of files) {
const reader = new FileReader();
reader.onload = () => {
this.addAttachment(file.name, reader.result);
};
reader.readAsArrayBuffer(file);
}
}
addAttachment(name, data) {
@ -989,7 +985,7 @@ class DetailsView extends View {
if (AutoType.enabled) {
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) {

View File

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

View File

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

View File

@ -94,7 +94,7 @@ class GeneratorView extends View {
(!this.model.password.isProtected || this.model.password.byteLength)
) {
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.preset = 'Derived';
} else {

View File

@ -115,7 +115,7 @@ class ListSearchView extends View {
title: true
};
if (this.model.advancedSearch) {
this.advancedSearch = _.extend({}, this.model.advancedSearch);
this.advancedSearch = Object.assign({}, this.model.advancedSearch);
}
this.setLocale();
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) {
this.views.openConfig.remove();
}
const config = _.extend(
const config = Object.assign(
{
id: storage.name,
name: Locale[storage.name] || storage.name,

View File

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