chore: use native String#{end,start}sWith
Supported since Node 4
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import fromCallback from 'promise-toolbox/fromCallback'
|
||||
import splitHost from 'split-host' // eslint-disable-line node/no-extraneous-import node/no-missing-import
|
||||
import startsWith from 'lodash/startsWith'
|
||||
import { createClient, Facility, Severity, Transport } from 'syslog-client' // eslint-disable-line node/no-extraneous-import node/no-missing-import
|
||||
|
||||
import LEVELS from '../levels'
|
||||
@@ -19,10 +18,10 @@ const facility = Facility.User
|
||||
export default target => {
|
||||
const opts = {}
|
||||
if (target !== undefined) {
|
||||
if (startsWith(target, 'tcp://')) {
|
||||
if (target.startsWith('tcp://')) {
|
||||
target = target.slice(6)
|
||||
opts.transport = Transport.Tcp
|
||||
} else if (startsWith(target, 'udp://')) {
|
||||
} else if (target.startsWith('udp://')) {
|
||||
target = target.slice(6)
|
||||
opts.transport = Transport.Udp
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ const nicePipe = require('nice-pipe')
|
||||
const pairs = require('lodash/toPairs')
|
||||
const pick = require('lodash/pick')
|
||||
const pump = require('pump')
|
||||
const startsWith = require('lodash/startsWith')
|
||||
const prettyMs = require('pretty-ms')
|
||||
const progressStream = require('progress-stream')
|
||||
const pw = require('pw')
|
||||
@@ -81,7 +80,7 @@ function parseParameters(args) {
|
||||
const name = matches[1]
|
||||
let value = matches[2]
|
||||
|
||||
if (startsWith(value, 'json:')) {
|
||||
if (value.startsWith('json:')) {
|
||||
value = JSON.parse(value.slice(5))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import JsonRpcWebSocketClient, { OPEN, CLOSED } from 'jsonrpc-websocket-client'
|
||||
import { BaseError } from 'make-error'
|
||||
import { startsWith } from 'lodash'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -35,7 +34,7 @@ export default class Xo extends JsonRpcWebSocketClient {
|
||||
}
|
||||
|
||||
call(method, args, i) {
|
||||
if (startsWith(method, 'session.')) {
|
||||
if (method.startsWith('session.')) {
|
||||
return Promise.reject(
|
||||
new XoError('session.*() methods are disabled from this interface')
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ import includes from 'lodash/includes'
|
||||
import proxyConsole from './proxy-console'
|
||||
import pw from 'pw'
|
||||
import serveStatic from 'serve-static'
|
||||
import startsWith from 'lodash/startsWith'
|
||||
import stoppable from 'stoppable'
|
||||
import WebServer from 'http-server-plus'
|
||||
import WebSocket from 'ws'
|
||||
@@ -332,7 +331,7 @@ async function registerPluginsInPath(path) {
|
||||
|
||||
await Promise.all(
|
||||
mapToArray(files, name => {
|
||||
if (startsWith(name, PLUGIN_PREFIX)) {
|
||||
if (name.startsWith(PLUGIN_PREFIX)) {
|
||||
return registerPluginWrapper.call(
|
||||
this,
|
||||
`${path}/${name}`,
|
||||
@@ -428,7 +427,7 @@ const setUpProxies = (express, opts, xo) => {
|
||||
const { url } = req
|
||||
|
||||
for (const prefix in opts) {
|
||||
if (startsWith(url, prefix)) {
|
||||
if (url.startsWith(prefix)) {
|
||||
const target = opts[prefix]
|
||||
|
||||
proxy.web(req, res, {
|
||||
@@ -452,7 +451,7 @@ const setUpProxies = (express, opts, xo) => {
|
||||
const { url } = req
|
||||
|
||||
for (const prefix in opts) {
|
||||
if (startsWith(url, prefix)) {
|
||||
if (url.startsWith(prefix)) {
|
||||
const target = opts[prefix]
|
||||
|
||||
proxy.ws(req, socket, head, {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { startsWith } from 'lodash'
|
||||
|
||||
import ensureArray from './_ensureArray'
|
||||
import {
|
||||
extractProperty,
|
||||
@@ -119,7 +117,7 @@ const TRANSFORMS = {
|
||||
size: update.installation_size,
|
||||
}
|
||||
|
||||
if (startsWith(update.name_label, 'XS')) {
|
||||
if (update.name_label.startsWith('XS')) {
|
||||
// It's a patch update but for homogeneity, we're still using pool_patches
|
||||
} else {
|
||||
supplementalPacks.push(formattedUpdate)
|
||||
|
||||
@@ -4,7 +4,6 @@ import synchronized from 'decorator-synchronized'
|
||||
import { BaseError } from 'make-error'
|
||||
import {
|
||||
defaults,
|
||||
endsWith,
|
||||
findKey,
|
||||
forEach,
|
||||
identity,
|
||||
@@ -184,7 +183,7 @@ const STATS = {
|
||||
transformValue: value => value * 1024,
|
||||
},
|
||||
memory: {
|
||||
test: metricType => endsWith(metricType, 'memory'),
|
||||
test: metricType => metricType.endsWith('memory'),
|
||||
},
|
||||
cpus: {
|
||||
test: /^cpu(\d+)$/,
|
||||
|
||||
@@ -31,7 +31,6 @@ import {
|
||||
isEmpty,
|
||||
noop,
|
||||
omit,
|
||||
startsWith,
|
||||
uniq,
|
||||
} from 'lodash'
|
||||
import { satisfies as versionSatisfies } from 'semver'
|
||||
@@ -830,7 +829,7 @@ export default class Xapi extends XapiBase {
|
||||
}
|
||||
|
||||
// If the VDI name start with `[NOBAK]`, do not export it.
|
||||
if (startsWith(vdi.name_label, '[NOBAK]')) {
|
||||
if (vdi.name_label.startsWith('[NOBAK]')) {
|
||||
// FIXME: find a way to not create the VDI snapshot in the
|
||||
// first time.
|
||||
//
|
||||
|
||||
@@ -10,17 +10,7 @@ import { createReadStream, readdir, stat } from 'fs'
|
||||
import { satisfies as versionSatisfies } from 'semver'
|
||||
import { utcFormat } from 'd3-time-format'
|
||||
import { basename, dirname } from 'path'
|
||||
import {
|
||||
endsWith,
|
||||
filter,
|
||||
find,
|
||||
includes,
|
||||
once,
|
||||
range,
|
||||
sortBy,
|
||||
startsWith,
|
||||
trim,
|
||||
} from 'lodash'
|
||||
import { filter, find, includes, once, range, sortBy, trim } from 'lodash'
|
||||
import {
|
||||
chainVhd,
|
||||
createSyntheticStream as createVhdReadStream,
|
||||
@@ -104,7 +94,7 @@ const getVdiTimestamp = name => {
|
||||
|
||||
const getDeltaBackupNameWithoutExt = name =>
|
||||
name.slice(0, -DELTA_BACKUP_EXT_LENGTH)
|
||||
const isDeltaBackup = name => endsWith(name, DELTA_BACKUP_EXT)
|
||||
const isDeltaBackup = name => name.endsWith(DELTA_BACKUP_EXT)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
@@ -308,13 +298,13 @@ export default class {
|
||||
const handler = await this._xo.getRemoteHandler(remoteId)
|
||||
|
||||
// List backups. (No delta)
|
||||
const backupFilter = file => endsWith(file, '.xva')
|
||||
const backupFilter = file => file.endsWith('.xva')
|
||||
|
||||
const files = await handler.list('.')
|
||||
const backups = filter(files, backupFilter)
|
||||
|
||||
// List delta backups.
|
||||
const deltaDirs = filter(files, file => startsWith(file, 'vm_delta_'))
|
||||
const deltaDirs = filter(files, file => file.startsWith('vm_delta_'))
|
||||
|
||||
for (const deltaDir of deltaDirs) {
|
||||
const files = await handler.list(deltaDir)
|
||||
@@ -336,12 +326,12 @@ export default class {
|
||||
const backups = []
|
||||
|
||||
await asyncMap(handler.list('.'), entry => {
|
||||
if (endsWith(entry, '.xva')) {
|
||||
if (entry.endsWith('.xva')) {
|
||||
backups.push(parseVmBackupPath(entry))
|
||||
} else if (startsWith(entry, 'vm_delta_')) {
|
||||
} else if (entry.startsWith('vm_delta_')) {
|
||||
return handler.list(entry).then(children =>
|
||||
asyncMap(children, child => {
|
||||
if (endsWith(child, '.json')) {
|
||||
if (child.endsWith('.json')) {
|
||||
const path = `${entry}/${child}`
|
||||
|
||||
const record = parseVmBackupPath(path)
|
||||
@@ -1007,7 +997,7 @@ export default class {
|
||||
// Currently, the filenames of the VHD changes over time
|
||||
// (delta → full), but the JSON is not updated, therefore the
|
||||
// VHD path may need to be fixed.
|
||||
return endsWith(vhdPath, '_delta.vhd')
|
||||
return vhdPath.endsWith('_delta.vhd')
|
||||
? pFromCallback(cb => stat(vhdPath, cb)).then(
|
||||
() => vhdPath,
|
||||
error => {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import endsWith from 'lodash/endsWith'
|
||||
import levelup from 'level-party'
|
||||
import startsWith from 'lodash/startsWith'
|
||||
import sublevel from 'level-sublevel'
|
||||
import { ensureDir } from 'fs-extra'
|
||||
|
||||
@@ -38,7 +36,7 @@ const levelPromise = db => {
|
||||
return
|
||||
}
|
||||
|
||||
if (endsWith(name, 'Stream') || startsWith(name, 'is')) {
|
||||
if (name.endsWith('Stream') || name.startsWith('is')) {
|
||||
dbP[name] = db::value
|
||||
} else {
|
||||
dbP[name] = promisify(value, db)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import PropTypes from 'prop-types'
|
||||
import React from 'react'
|
||||
import { isFunction, startsWith } from 'lodash'
|
||||
import { isFunction } from 'lodash'
|
||||
|
||||
import Button from './button'
|
||||
import Component from './base-component'
|
||||
@@ -73,7 +73,7 @@ export default class ActionButton extends Component {
|
||||
let empty = true
|
||||
handlerParam = {}
|
||||
Object.keys(props).forEach(key => {
|
||||
if (startsWith(key, 'data-')) {
|
||||
if (key.startsWith('data-')) {
|
||||
empty = false
|
||||
handlerParam[key.slice(5)] = props[key]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import classNames from 'classnames'
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { isEmpty, isFunction, isString, map, pick, startsWith } from 'lodash'
|
||||
import { isEmpty, isFunction, isString, map, pick } from 'lodash'
|
||||
|
||||
import _ from '../intl'
|
||||
import Component from '../base-component'
|
||||
@@ -119,7 +119,7 @@ class Editable extends Component {
|
||||
this.setState({ saving: true })
|
||||
|
||||
const params = Object.keys(props).reduce((res, val) => {
|
||||
if (startsWith(val, 'data-')) {
|
||||
if (val.startsWith('data-')) {
|
||||
res[val.slice(5)] = props[val]
|
||||
}
|
||||
return res
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import PropTypes from 'prop-types'
|
||||
import React from 'react'
|
||||
import { injectState, provideState } from 'reaclette'
|
||||
import { startsWith } from 'lodash'
|
||||
|
||||
import decorate from '../apply-decorators'
|
||||
|
||||
@@ -23,7 +22,7 @@ const Number_ = decorate([
|
||||
const params = {}
|
||||
let empty = true
|
||||
Object.keys(props).forEach(key => {
|
||||
if (startsWith(key, 'data-')) {
|
||||
if (key.startsWith('data-')) {
|
||||
empty = false
|
||||
params[key.slice(5)] = props[key]
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import CopyToClipboard from 'react-copy-to-clipboard'
|
||||
import PropTypes from 'prop-types'
|
||||
import React from 'react'
|
||||
import { get } from '@xen-orchestra/defined'
|
||||
import { find, startsWith } from 'lodash'
|
||||
import { find } from 'lodash'
|
||||
|
||||
import decorate from './apply-decorators'
|
||||
import Icon from './icon'
|
||||
@@ -492,7 +492,7 @@ const xoItemToRender = {
|
||||
|
||||
gpuGroup: group => (
|
||||
<span>
|
||||
{startsWith(group.name_label, 'Group of ')
|
||||
{group.name_label.startsWith('Group of ')
|
||||
? group.name_label.slice(9)
|
||||
: group.name_label}
|
||||
</span>
|
||||
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
isFunction,
|
||||
map,
|
||||
sortBy,
|
||||
startsWith,
|
||||
} from 'lodash'
|
||||
|
||||
import ActionRowButton from '../action-row-button'
|
||||
@@ -327,7 +326,7 @@ export default class SortedTable extends Component {
|
||||
const { props } = this
|
||||
const userData = {}
|
||||
Object.keys(props).forEach(key => {
|
||||
if (startsWith(key, 'data-')) {
|
||||
if (key.startsWith('data-')) {
|
||||
userData[key.slice(5)] = props[key]
|
||||
}
|
||||
})
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
replace,
|
||||
sample,
|
||||
some,
|
||||
startsWith,
|
||||
} from 'lodash'
|
||||
|
||||
import _ from './intl'
|
||||
@@ -477,7 +476,7 @@ export const compareVersions = makeNiceCompare((v1, v2) => {
|
||||
return 0
|
||||
})
|
||||
|
||||
export const isXosanPack = ({ name }) => startsWith(name, 'XOSAN')
|
||||
export const isXosanPack = ({ name }) => name.startsWith('XOSAN')
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import _ from 'intl'
|
||||
import ActionButton from 'action-button'
|
||||
import Component from 'base-component'
|
||||
import endsWith from 'lodash/endsWith'
|
||||
import Icon from 'icon'
|
||||
import React from 'react'
|
||||
import replace from 'lodash/replace'
|
||||
@@ -192,7 +191,7 @@ export default class RestoreFileModalBody extends Component {
|
||||
select.blur()
|
||||
select.focus()
|
||||
|
||||
const isFile = file.id !== '..' && !endsWith(file.path, '/')
|
||||
const isFile = file.id !== '..' && !file.path.endsWith('/')
|
||||
if (isFile) {
|
||||
const { selectedFiles } = this.state
|
||||
if (!includes(selectedFiles, file)) {
|
||||
@@ -228,7 +227,7 @@ export default class RestoreFileModalBody extends Component {
|
||||
_selectAllFolderFiles = () => {
|
||||
this.setState({
|
||||
selectedFiles: (this.state.selectedFiles || []).concat(
|
||||
filter(this._getSelectableFiles(), ({ path }) => !endsWith(path, '/'))
|
||||
filter(this._getSelectableFiles(), ({ path }) => !path.endsWith('/'))
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,16 +10,7 @@ import { dirname } from 'path'
|
||||
import { Container, Col, Row } from 'grid'
|
||||
import { createSelector } from 'reselect'
|
||||
import { formatSize } from 'utils'
|
||||
import {
|
||||
endsWith,
|
||||
filter,
|
||||
find,
|
||||
forEach,
|
||||
includes,
|
||||
isEmpty,
|
||||
map,
|
||||
startsWith,
|
||||
} from 'lodash'
|
||||
import { filter, find, forEach, includes, isEmpty, map } from 'lodash'
|
||||
import { getRenderXoItemOfType } from 'render-xo-item'
|
||||
import { listPartitions, listFiles } from 'xo'
|
||||
|
||||
@@ -46,7 +37,7 @@ const fileOptionRenderer = ({ isFile, name }) => (
|
||||
</span>
|
||||
)
|
||||
|
||||
const ensureTrailingSlash = path => path + (endsWith(path, '/') ? '' : '/')
|
||||
const ensureTrailingSlash = path => path + (path.endsWith('/') ? '' : '/')
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -66,7 +57,7 @@ const formatFilesOptions = (rawFiles, path) => {
|
||||
return files.concat(
|
||||
map(rawFiles, (_, name) => ({
|
||||
id: `${path}${name}`,
|
||||
isFile: !endsWith(name, '/'),
|
||||
isFile: !name.endsWith('/'),
|
||||
name,
|
||||
path: `${path}${name}`,
|
||||
}))
|
||||
@@ -262,7 +253,7 @@ export default class RestoreFileModalBody extends Component {
|
||||
redundantFiles[file.path] =
|
||||
find(
|
||||
files,
|
||||
f => !f.isFile && f !== file && startsWith(file.path, f.path)
|
||||
f => !f.isFile && f !== file && file.path.startsWith(f.path)
|
||||
) !== undefined
|
||||
})
|
||||
return redundantFiles
|
||||
|
||||
@@ -22,7 +22,7 @@ import { createGetObjectsOfType, getUser } from 'selectors'
|
||||
import { createSelector } from 'reselect'
|
||||
import { generateUiSchema } from 'xo-json-schema-input'
|
||||
import { SelectSubject } from 'select-objects'
|
||||
import { forEach, isArray, map, mapValues, noop, startsWith } from 'lodash'
|
||||
import { forEach, isArray, map, mapValues, noop } from 'lodash'
|
||||
|
||||
import { createJob, createSchedule, getRemote, editJob, editSchedule } from 'xo'
|
||||
|
||||
@@ -479,7 +479,7 @@ export default class New extends Component {
|
||||
|
||||
if (remoteId) {
|
||||
const remote = await getRemote(remoteId)
|
||||
if (startsWith(remote.url, 'file:')) {
|
||||
if (remote.url.startsWith('file:')) {
|
||||
await confirm({
|
||||
title: _('localRemoteWarningTitle'),
|
||||
body: _('localRemoteWarningMessage'),
|
||||
|
||||
Reference in New Issue
Block a user