Skip to content

Commit

Permalink
refactor: convert deprecated substr to slice
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jan 5, 2024
1 parent 132f74b commit 361df0a
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/core/lib/actions/fs/assert/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/actions/fs/base/chmod/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/actions/fs/base/mkdir/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/plugins/magic_dollar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/lib/session/contextualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/utils/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/file/lib/cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/file/lib/download/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
},
},
Expand Down
10 changes: 5 additions & 5 deletions packages/file/lib/utils/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 {
Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ldap/lib/acl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/network/lib/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/test/cron/add.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/test/cron/remove.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 361df0a

Please sign in to comment.