Skip to content

Commit

Permalink
refactor: substr(ing) > slice
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Dec 13, 2021
1 parent 2ac6a34 commit 1ac434a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/update-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ const props = [

if (nextIsOption) {
nextIsOption = false;
option = blocks[strLine.substring(2)] = new Block(); // eslint-disable-line no-multi-assign
option = blocks[strLine.slice(2)] = new Block(); // eslint-disable-line no-multi-assign
return;
}

const next = props.find((prop) => {
if (
prop.startsWith('@')
? strLine.substring(2, 2 + prop.length) === prop
: strLine.substring(2, 2 + prop.length + 1) === `${prop}:`
? strLine.slice(2, 2 + prop.length) === prop
: strLine.slice(2, 2 + prop.length + 1) === `${prop}:`
) {
let override;
if (prop === 'example' && option.example) {
Expand Down
4 changes: 2 additions & 2 deletions example/views/repost.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<script nonce="<%= nonce %>">
function parseQuery(queryString) {
var query = {};
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
var pairs = (queryString[0] === '?' ? queryString.slice(1) : queryString).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return query;
}
var fields = parseQuery(window.location.hash.substring(1));
var fields = parseQuery(window.location.hash.slice(1));
fields.upstream = '<%= upstream %>'
var uid = fields.state.split('|')[0]
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const keyscore = (key, { alg, use }) => {
};

const getKtyFromJWSAlg = (alg) => {
switch (alg.substr(0, 2)) {
switch (alg.slice(0, 2)) {
case 'RS':
case 'PS': return 'RSA';
case 'HS': return 'oct';
Expand All @@ -39,7 +39,7 @@ const getCrvFromJWSAlg = (alg) => {
};

const getKtyFromJWEAlg = (alg, epk) => {
switch (alg.substr(0, 1)) {
switch (alg[0]) {
case 'A':
case 'P': return 'oct';
case 'R': return 'RSA';
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/oidc_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function getContext(provider) {
}

urlFor(name, opt) {
const mountPath = (this.ctx.req.originalUrl && this.ctx.req.originalUrl.substring(
const mountPath = (this.ctx.req.originalUrl && this.ctx.req.originalUrl.slice(
0,
this.ctx.req.originalUrl.indexOf(this.ctx.request.url),
))
Expand Down
2 changes: 1 addition & 1 deletion lib/models/formats/paseto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { strict: assert } = require('assert');
const crypto = require('crypto');

let paseto;
let paseto3 = process.version.substr(1).split('.').map((x) => parseInt(x, 10))[0] >= 16;
let paseto3 = parseInt(process.versions.node, 10) >= 16;

if (paseto3) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const attention = require('./helpers/attention');

const [major, minor] = process.version
.substr(1)
.slice(1)
.split('.')
.map((str) => parseInt(str, 10));

Expand Down
2 changes: 1 addition & 1 deletion test/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function report() {
const mountTo = '/oidc';
const frameworks = ['connect', 'express', 'fastify', 'koa'];

if (process.version.substr(1).split('.').map((x) => parseInt(x, 10))[0] >= 12) {
if (process.version.slice(1).split('.').map((x) => parseInt(x, 10))[0] >= 12) {
frameworks.push('hapi');
}

Expand Down
2 changes: 1 addition & 1 deletion test/formats/paseto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sinon = require('sinon').createSandbox();
const { expect } = require('chai');

let paseto;
const above16 = process.version.substr(1).split('.').map((x) => parseInt(x, 10))[0] >= 16;
const above16 = parseInt(process.versions.node, 10) >= 16;
if (above16) {
// eslint-disable-next-line
paseto = require('paseto3');
Expand Down

0 comments on commit 1ac434a

Please sign in to comment.