From 361df0af63f25b8a29d3ea51b6e86768357ca877 Mon Sep 17 00:00:00 2001 From: David Worms Date: Fri, 5 Jan 2024 12:05:04 +0100 Subject: [PATCH] refactor: convert deprecated substr to slice --- packages/core/lib/actions/fs/assert/index.js | 2 +- packages/core/lib/actions/fs/base/chmod/index.js | 2 +- packages/core/lib/actions/fs/base/mkdir/index.js | 2 +- packages/core/lib/plugins/magic_dollar.js | 2 +- packages/core/lib/session/contextualize.js | 3 ++- packages/core/lib/utils/mode.js | 4 ++-- packages/file/lib/cache/index.js | 2 +- packages/file/lib/download/index.js | 2 +- packages/file/lib/utils/partial.js | 10 +++++----- packages/ldap/lib/acl/index.js | 2 +- packages/network/lib/http/index.js | 2 +- packages/tools/test/cron/add.coffee | 2 +- packages/tools/test/cron/remove.coffee | 2 +- 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/core/lib/actions/fs/assert/index.js b/packages/core/lib/actions/fs/assert/index.js index 7e410c0c7..fda3e8a4d 100644 --- a/packages/core/lib/actions/fs/assert/index.js +++ b/packages/core/lib/actions/fs/assert/index.js @@ -63,7 +63,7 @@ const errors = { const expect = config.mode.map(function(mode) { return pad(4, utils.mode.stringify(mode), '0'); }); - return utils.error("NIKITA_FS_ASSERT_MODE_UNMATCH", ['content permission don\'t match the provided mode,', `expect ${expect},`, `got ${utils.mode.stringify(mode).substr(-4)}.`], { + return utils.error("NIKITA_FS_ASSERT_MODE_UNMATCH", ['content permission don\'t match the provided mode,', `expect ${expect},`, `got ${utils.mode.stringify(mode).slice(-4)}.`], { target: config.target, message: config.error }); diff --git a/packages/core/lib/actions/fs/base/chmod/index.js b/packages/core/lib/actions/fs/base/chmod/index.js index f1043122a..68f4fed05 100644 --- a/packages/core/lib/actions/fs/base/chmod/index.js +++ b/packages/core/lib/actions/fs/base/chmod/index.js @@ -6,7 +6,7 @@ import definitions from "./schema.json" assert { type: "json" }; export default { handler: async function({config}) { const mode = typeof config.mode === 'number' - ? config.mode.toString(8).substr(-4) + ? config.mode.toString(8).slice(-4) : config.mode; await this.execute(`chmod ${mode} ${config.target}`); }, diff --git a/packages/core/lib/actions/fs/base/mkdir/index.js b/packages/core/lib/actions/fs/base/mkdir/index.js index c96ccb6d2..76f2a6f54 100644 --- a/packages/core/lib/actions/fs/base/mkdir/index.js +++ b/packages/core/lib/actions/fs/base/mkdir/index.js @@ -18,7 +18,7 @@ export default { handler: async function({config}) { if (typeof config.mode === 'number') { // Convert mode into a string - config.mode = config.mode.toString(8).substr(-4); + config.mode = config.mode.toString(8).slice(-4); } try { return (await this.execute([`[ -d '${config.target}' ] && exit 17`, ['install', config.mode ? `-m '${config.mode}'` : void 0, config.uid ? `-o '${config.uid}'` : void 0, config.gid ? `-g '${config.gid}'` : void 0, `-d '${config.target}'`].join(' ')].join('\n'))); diff --git a/packages/core/lib/plugins/magic_dollar.js b/packages/core/lib/plugins/magic_dollar.js index 55d0248da..6a53f1941 100644 --- a/packages/core/lib/plugins/magic_dollar.js +++ b/packages/core/lib/plugins/magic_dollar.js @@ -16,7 +16,7 @@ export default { if (k[0] !== "$") { continue; } - const prop = k.substr(1); + const prop = k.slice(1); switch (prop) { case "handler": action.handler = v; diff --git a/packages/core/lib/session/contextualize.js b/packages/core/lib/session/contextualize.js index e95e89261..f1d0ea004 100644 --- a/packages/core/lib/session/contextualize.js +++ b/packages/core/lib/session/contextualize.js @@ -78,7 +78,8 @@ export default function (args) { if (k === "$$") { mutate(new_action.metadata, v); } else { - const prop = k.substr(1); + // Extract the property name from key starting with `$` + const prop = k.slice(1); if (properties.includes(prop)) { new_action[prop] = v; } else { diff --git a/packages/core/lib/utils/mode.js b/packages/core/lib/utils/mode.js index a205804e4..27bea7bbd 100644 --- a/packages/core/lib/utils/mode.js +++ b/packages/core/lib/utils/mode.js @@ -14,9 +14,9 @@ const compare = function (...modes) { for (let i = 1; i < modes.length; i++) { const mode = this.stringify(modes[i]); if ( - !ref.some(function (m) { + !ref.some( (m) => { const l = Math.min(m.length, mode.length); - return m.substr(-l) === mode.substr(-l); + return m.slice(-l) === mode.slice(-l); }) ) { return false; diff --git a/packages/file/lib/cache/index.js b/packages/file/lib/cache/index.js index ff5c23fe5..9a3bf4b81 100644 --- a/packages/file/lib/cache/index.js +++ b/packages/file/lib/cache/index.js @@ -27,7 +27,7 @@ export default { } config.target = path.resolve(config.cache_dir, config.target); if (/^file:\/\//.test(config.source)) { - config.source = config.source.substr(7); + config.source = config.source.slice(7); } // todo, also support config.algo and config.hash // replace alog and _hash with diff --git a/packages/file/lib/download/index.js b/packages/file/lib/download/index.js index a37054a31..2b86e2fdb 100644 --- a/packages/file/lib/download/index.js +++ b/packages/file/lib/download/index.js @@ -309,7 +309,7 @@ export default { ); config.cache_dir = await find(({ config: { cache_dir } }) => cache_dir); if (/^file:\/\//.test(config.source)) { - return (config.source = config.source.substr(7)); + return (config.source = config.source.slice(7)); } }, }, diff --git a/packages/file/lib/utils/partial.js b/packages/file/lib/utils/partial.js index 5a2ac78aa..c6998f79b 100644 --- a/packages/file/lib/utils/partial.js +++ b/packages/file/lib/utils/partial.js @@ -54,7 +54,7 @@ export default function(config, log) { } } else { log("DEBUG", "Forgot how we could get there, test shall say it all"); - const linebreak = config.content.length === 0 || config.content.substr(config.content.length - 1) === '\n' ? '' : '\n'; + const linebreak = config.content.length === 0 || config.content.slice(config.content.length - 1) === '\n' ? '' : '\n'; config.content = opts.replace + linebreak + config.content; } } else if (opts.append && typeof opts.replace === 'string') { @@ -77,7 +77,7 @@ export default function(config, log) { } } } else { - const linebreak = config.content.length === 0 || config.content.substr(config.content.length - 1) === '\n' ? '' : '\n'; + const linebreak = config.content.length === 0 || config.content.slice(config.content.length - 1) === '\n' ? '' : '\n'; config.content = config.content + linebreak + opts.replace; } } else { @@ -100,19 +100,19 @@ export default function(config, log) { log("WARN", "Missing 'from' and 'to' without append, skip writing"); } } else { - config.content = config.content.substr(0, from.index + from[1].length + 1) + opts.replace + '\n' + config.content.substr(to.index); + config.content = config.content.slice(0, from.index + from[1].length + 1) + opts.replace + '\n' + config.content.slice(to.index); } } else if (opts.from && !opts.to) { const from = RegExp(`(^${utils.regexp.quote(opts.from)}$)`, "m").exec(config.content); if (from != null) { - config.content = config.content.substr(0, from.index + from[1].length) + '\n' + opts.replace; // TODO: honors append + config.content = config.content.slice(0, from.index + from[1].length) + '\n' + opts.replace; // TODO: honors append } else { log("WARN", "Missing 'from', skip writing"); } } else if (!opts.from && opts.to) { const to = RegExp(`(^${utils.regexp.quote(opts.to)}$)`, "m").exec(config.content); if (to != null) { - config.content = opts.replace + '\n' + config.content.substr(to.index); // TODO: honors append + config.content = opts.replace + '\n' + config.content.slice(to.index); // TODO: honors append } else { log("WARN", "Missing 'to', skip writing"); } diff --git a/packages/ldap/lib/acl/index.js b/packages/ldap/lib/acl/index.js index 553f1277f..310ad7a0a 100644 --- a/packages/ldap/lib/acl/index.js +++ b/packages/ldap/lib/acl/index.js @@ -36,7 +36,7 @@ export default { } else if (current != null) { if (/^ /.test(line)) { // Append to existing rule - current += line.substr(1); // Close the rule + current += line.slice(1); // Close the rule } else { olcAccesses.push(current); current = null; diff --git a/packages/network/lib/http/index.js b/packages/network/lib/http/index.js index 57862867e..a79c2e61b 100644 --- a/packages/network/lib/http/index.js +++ b/packages/network/lib/http/index.js @@ -95,7 +95,7 @@ export default { output.headers = {}; const [http_version, status_code, ...status_message] = line.split(" "); - output.http_version = http_version.substr(5); + output.http_version = http_version.slice(5); output.status_code = parseInt(status_code, 10); output.status_message = status_message.join(" "); continue; diff --git a/packages/tools/test/cron/add.coffee b/packages/tools/test/cron/add.coffee index 217f88f10..0c2a58a4c 100644 --- a/packages/tools/test/cron/add.coffee +++ b/packages/tools/test/cron/add.coffee @@ -69,7 +69,7 @@ describe 'tools.cron.add', -> describe 'action', -> - rand = Math.random().toString(36).substring(7) + rand = Math.random().toString(36).slice(7) they 'add a job', ({ssh}) -> nikita diff --git a/packages/tools/test/cron/remove.coffee b/packages/tools/test/cron/remove.coffee index d194954cb..503405662 100644 --- a/packages/tools/test/cron/remove.coffee +++ b/packages/tools/test/cron/remove.coffee @@ -24,7 +24,7 @@ describe 'tools.cron.remove', -> describe 'action', -> - rand = Math.random().toString(36).substring(7) + rand = Math.random().toString(36).slice(7) they 'remove a job', ({ssh}) -> nikita