Skip to content

Commit

Permalink
refactor: replace deprecated .substr() w/ .substring()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 1, 2022
1 parent f798c9d commit 0710509
Show file tree
Hide file tree
Showing 54 changed files with 177 additions and 153 deletions.
11 changes: 8 additions & 3 deletions examples/cellular-automata/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { dropdown, type DropDownOption } from "@thi.ng/hdom-components/dropdown";
import {
dropdown,
type DropDownOption,
} from "@thi.ng/hdom-components/dropdown";
import { start } from "@thi.ng/hdom/start";
import { bits } from "@thi.ng/transducers-binary/bits";
import { comp } from "@thi.ng/transducers/comp";
Expand Down Expand Up @@ -130,12 +133,14 @@ const isPreset = (id: string) => presets.findIndex((x) => x[0] === id) !== -1;

// Use Conway CA default state rules [[dead], [alive]] if no preset present in hash
applyRules(
location.hash.length > 18 ? location.hash.substr(1) : <string>presets[1][0]
location.hash.length > 18
? location.hash.substring(1)
: <string>presets[1][0]
);

// define & start main app component
start(() => {
const id = location.hash.substr(1);
const id = location.hash.substring(1);
return [
"div",
ruleBoxes("birth", 0),
Expand Down
4 changes: 2 additions & 2 deletions examples/color-themes/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const initFromHash = (
) => {
// attempt to restore state from hash fragment
if (location.hash.length > 1) {
const tokens = atob(location.hash.substr(1)).split("|");
const tokens = window.atob(location.hash.substring(1)).split("|");
if (tokens.length === NUM_STATE_TOKENS) {
seed.next(parseInt(tokens[0]));
num.next(parseInt(tokens[1]));
Expand All @@ -31,7 +31,7 @@ export const initFromHash = (
/**
* Attaches subscription to store current config base64 encoded in hash fragment
*
* @param parent -
* @param parent -
*/
export const attachSerializer = (parent: ISubscribable<MainOutputs>) =>
parent.subscribe({
Expand Down
8 changes: 4 additions & 4 deletions examples/commit-table-ssr/src/common/components/repo-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { table } from "./table";
* Git commit log table component. Consumes iterable of `Commit` objects
* and transforms each into a table row.
*
* @param _ -
* @param commits -
* @param _ -
* @param commits -
*/
export const repoTable = (_: AppContext, commits: Iterable<Commit>) => [
table,
Expand All @@ -23,7 +23,7 @@ export const repoTable = (_: AppContext, commits: Iterable<Commit>) => [
comp(
// convert commit into tuple, one value per table cell
map((x: Commit) => [
x.date.substr(0, 10),
x.date.substring(0, 10),
x.author,
[commitLink, x.sha, x.msg],
x.files,
Expand All @@ -34,7 +34,7 @@ export const repoTable = (_: AppContext, commits: Iterable<Commit>) => [
partitionBy((row: any[]) => row[0].split("-")[1]),
// insert month headers (but not in 1st chunk)
mapIndexed((i, month) => [
i > 0 ? [month[0][0].substr(0, 7), ...repeat("", 5)] : null,
i > 0 ? [month[0][0].substring(0, 7), ...repeat("", 5)] : null,
month,
])
),
Expand Down
7 changes: 5 additions & 2 deletions examples/crypto-chart/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Fn, IObjectOf } from "@thi.ng/api";
import { dropdown, type DropDownOption } from "@thi.ng/hdom-components/dropdown";
import {
dropdown,
type DropDownOption,
} from "@thi.ng/hdom-components/dropdown";
import { group } from "@thi.ng/hiccup-svg/group";
import { line } from "@thi.ng/hiccup-svg/line";
import { polygon } from "@thi.ng/hiccup-svg/polygon";
Expand Down Expand Up @@ -163,7 +166,7 @@ const THEMES: any = {
const API_URL = (market: string, symbol: string, period: number) =>
`https://min-api.cryptocompare.com/data/histo${TIMEFRAMES[
period
].toLowerCase()}?fsym=${symbol.substr(0, 3)}&tsym=${symbol.substr(
].toLowerCase()}?fsym=${symbol.substring(0, 3)}&tsym=${symbol.substring(
3
)}&limit=168&aggregate=1&e=${market}`;

Expand Down
2 changes: 1 addition & 1 deletion examples/hdom-canvas-shapes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ sync({
// seed initial test selection
selection.next(
window.location.hash.length > 1
? window.location.hash.substr(1).replace(/-/g, " ")
? window.location.hash.substring(1).replace(/-/g, " ")
: "shape morph"
);

Expand Down
8 changes: 6 additions & 2 deletions examples/hdom-dropdown-fuzzy/src/fuzzy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { comp } from "@thi.ng/transducers/comp";
import { filterFuzzy } from "@thi.ng/transducers/filter-fuzzy";
import { iterator } from "@thi.ng/transducers/iterator";
import { map } from "@thi.ng/transducers/map";
import { dropdownListeners, type DropdownItem, type DropdownState } from "./dropdown";
import {
dropdownListeners,
type DropdownItem,
type DropdownState,
} from "./dropdown";

export interface FuzzyArgs {
state: IView<DropdownState>;
Expand Down Expand Up @@ -92,6 +96,6 @@ const highlightMatches = (
j++;
}
}
prev < n && res.push(x.substr(prev + 1));
prev < n && res.push(x.substring(prev + 1));
return res;
};
2 changes: 1 addition & 1 deletion examples/hdom-vscroller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const repoLink = (_: any, sha: string, body: any) => [

const packageLink = (_: any, name: any) => [
"a.link.blue",
{ href: `${REPO_BASE}tree/develop/packages/${name.substr(8)}` },
{ href: `${REPO_BASE}tree/develop/packages/${name.substring(8)}` },
name,
];

Expand Down
2 changes: 1 addition & 1 deletion examples/mandelbrot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ newRender.apply(
null,
<any>(
(location.hash.length > 1
? location.hash.substr(1).split(";").map(parseFloat)
? location.hash.substring(1).split(";").map(parseFloat)
: DEFAULT_CONFIG)
)
);
2 changes: 1 addition & 1 deletion examples/package-stats/src/dep-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fs.writeFileSync(
axis: [50, width - 15, 170],
domain: [0, packageDeps.length, 1],
range: [50, width - 5],
ticks: [...map((x) => x[0].substr(8), packageDeps)],
ticks: [...map((x) => x[0].substring(8), packageDeps)],
label: labeledTickX,
},
y: {
Expand Down
2 changes: 1 addition & 1 deletion examples/package-stats/src/size-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const meta = transduce(
);

writeFileSync(
`package-sizes-${new Date().toISOString().substr(0, 10)}.json`,
`package-sizes-${new Date().toISOString().substring(0, 10)}.json`,
JSON.stringify(meta, null, 4)
);
console.log(meta.length);
Expand Down
2 changes: 1 addition & 1 deletion examples/parse-playground/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
// this uses a base64 & msgpack encoded version of the two editors
const parseState = ((): Nullable<string[]> => {
try {
return deserialize(base64Decode(location.hash.substr(1)));
return deserialize(base64Decode(location.hash.substring(1)));
} catch (e) {}
})() || [DEFAULT_GRAMMAR, DEFAULT_RULE, ...DEFAULT_INPUTS];

Expand Down
2 changes: 1 addition & 1 deletion examples/rdom-basics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const typewriter = (min: number, max: number) => (src: string) =>
let active = true;
(async () => {
for (let i = 1; active && i <= src.length; i++) {
s.next(src.substr(0, i));
s.next(src.substring(0, i));
await delayed(0, Math.random() * (max - min) + min);
}
s.closeIn !== CloseMode.NEVER && s.done();
Expand Down
2 changes: 1 addition & 1 deletion examples/talk-slides/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const main = sync({
if (INTERACTIVE) {
main.transform(map(app(SLIDES.length, ctx)), updateDOM({ ctx }));
initKeys(slideCTRL);
slideCTRL.next(parseSlideID(location.hash.substr(1)));
slideCTRL.next(parseSlideID(location.hash.substring(1)));
} else {
renderOnce(() => [printApp, SLIDES], { ctx });
}
Expand Down
4 changes: 2 additions & 2 deletions packages/args/src/coerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function coerceKV(delim = "=", strict = false, multi = false) {
`got '${x}', but expected a 'key${delim}value' pair`
);
if (idx > 0) {
const id = x.substr(0, idx);
const val = x.substr(idx + 1);
const id = x.substring(0, idx);
const val = x.substring(idx + 1);
if (multi) {
acc[id] ? (<string[]>acc[id]).push(val) : (acc[id] = [val]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/args/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const parseKey = <T extends IObjectOf<any>>(
if (a[1] === "-") {
// terminator arg, stop parsing
if (a === "--") return { state: 1 };
id = camel(a.substr(2));
id = camel(a.substring(2));
} else {
id = aliases[a.substr(1)];
id = aliases[a.substring(1)];
!id && illegalArgs(`unknown option: ${a}`);
}
const spec: ArgSpecExt = specs[id];
Expand Down
6 changes: 3 additions & 3 deletions packages/date/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const FORMATTERS: Record<string, FormatFn> = {
* Returns literal `"Z"` iff timezone offset is zero (UTC), else the same as
* `Z` formatter.
*
* @param d -
* @param d -
*/
ZZ: (d, utc = false) => (utc ? "Z" : FORMATTERS.Z(d, utc)),
/**
Expand Down Expand Up @@ -164,7 +164,7 @@ export const FORMATTERS: Record<string, FormatFn> = {
* // "yyyy"
* ```
*
* @param fmt -
* @param fmt -
*/
export const defFormat =
(fmt: (string | FormatFn)[]) =>
Expand All @@ -176,7 +176,7 @@ export const defFormat =
let fn: FormatFn;
return isString(x)
? x.startsWith("\\")
? x.substr(1)
? x.substring(1)
: (fn = FORMATTERS[x])
? fn(d, utc)
: x
Expand Down
2 changes: 1 addition & 1 deletion packages/date/src/relative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const parseNum = (x: string, past: boolean) =>
const parsePeriod = (x: string) => {
x =
x !== "s" && x !== "ms" && x.endsWith("s")
? x.substr(0, x.length - 1)
? x.substring(0, x.length - 1)
: x;
return <Period>{
ms: "t",
Expand Down
22 changes: 11 additions & 11 deletions packages/egf/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const parse = (src: string, ctx: ParseContext) => {
};

const parseInclude = (line: string, ctx: ParseContext) => {
const path = unescape(line.substr(INCLUDE.length));
const path = unescape(line.substring(INCLUDE.length));
if (IS_NODE && ctx.opts.includes) {
$parseFile(path, {
...ctx,
Expand All @@ -69,7 +69,7 @@ const parsePrefix = (line: string, ctx: ParseContext) => {
if (idx > 0) {
const id = unescape(line.substring(PREFIX.length, idx));
if (RE_PREFIX.test(id)) {
const val = unescape(line.substr(idx + 2).trim());
const val = unescape(line.substring(idx + 2).trim());
if (val.length) {
ctx.logger.debug(`declare prefix: ${id} = ${val}`);
ctx.prefixes[id] = val;
Expand Down Expand Up @@ -107,7 +107,7 @@ const parseProp = (
ctx.index,
node,
key,
parseRef(unescape(line.substr(idx + 2).trim()), ctx)
parseRef(unescape(line.substring(idx + 2).trim()), ctx)
);
return ++i;
} else if (line[idx] === "#") {
Expand All @@ -117,7 +117,7 @@ const parseProp = (
idx++;
}
if (line[idx] === ">" && line[idx + 1] === ">" && line[idx + 2] === ">") {
body = line.substr(idx + 3);
body = line.substring(idx + 3);
idx = body.indexOf("<<<");
if (idx < 0) {
const n = lines.length;
Expand All @@ -126,7 +126,7 @@ const parseProp = (
line = lines[i];
idx = line.indexOf("<<<");
if (idx >= 0) {
body += "\n" + line.substr(0, idx);
body += "\n" + line.substring(0, idx);
closed = true;
i++;
break;
Expand All @@ -136,11 +136,11 @@ const parseProp = (
}
!closed && illegalState("unterminated value, EOF reached");
} else {
body = body.substr(0, idx);
body = body.substring(0, idx);
i++;
}
} else {
body = line.substr(idx);
body = line.substring(idx);
i++;
}
body = body.trim();
Expand Down Expand Up @@ -236,8 +236,8 @@ export const $parseFile = (path: string, ctx?: Partial<ParseContext>) => {
* Parses EGF graph from given local file name, using provided options (if any)
* to customize the parser. Returns object of graph `nodes` and `prefixes`.
*
* @param path -
* @param ctx -
* @param path -
* @param ctx -
*/
export const parseFile = (path: string, ctx?: Partial<ParseContext>) => {
const res = $parseFile(path, ctx);
Expand All @@ -248,8 +248,8 @@ export const parseFile = (path: string, ctx?: Partial<ParseContext>) => {
* Parses EGF graph from given string and provided options (if any) to customize
* the parser. Returns object of graph `nodes` and `prefixes`.
*
* @param path -
* @param ctx -
* @param path -
* @param ctx -
*/
export const parseString = (src: string, ctx?: Partial<ParseContext>) => {
const res = parse(src, initContext(ctx));
Expand Down
2 changes: 1 addition & 1 deletion packages/egf/src/prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const defPrefixer = (prefixes: Prefixes) => {
return (uri: string) => {
const known = uriToID.knownPrefix(uri);
return known
? uriToID.get(known)! + ":" + uri.substr(known.length)
? uriToID.get(known)! + ":" + uri.substring(known.length)
: undefined;
};
};
Expand Down
5 changes: 4 additions & 1 deletion packages/fsm/src/until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const untilStr =
return buf.endsWith(str)
? result(
callback &&
callback(ctx, buf.substr(0, buf.length - str.length))
callback(
ctx,
buf.substring(0, buf.length - str.length)
)
)
: RES_PARTIAL;
};
Expand Down
9 changes: 6 additions & 3 deletions packages/fuzzy-viz/src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ import { varToHiccup } from "./var.js";
* strategy.clear();
* ```
*
* @param strategy -
* @param instrument -
* @param strategy -
* @param instrument -
*/
export const instrumentStrategy = <T>(
strategy: DefuzzStrategy,
Expand Down Expand Up @@ -119,7 +119,10 @@ export const fuzzySetToAscii =
}
const index = Math.round(fit(res, min, max, 0, vals.length));
let chart = barChartHLines(height, vals, 0, 1)
.map((line) => line.substr(0, index) + "|" + line.substr(index + 1))
.map(
(line) =>
line.substring(0, index) + "|" + line.substring(index + 1)
)
.join("\n")
.replace(/ /g, empty);
const legend = repeat(" ", index) + "^ " + res.toFixed(2);
Expand Down
2 changes: 1 addition & 1 deletion packages/geom-io-obj/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const parseOBJ = (src: string, opts?: Partial<ParseOpts>) => {
const l = lines[i];
if (!l.length) continue;
if (l[0] === "#") {
comments && result.comments.push(l.substr(1).trim());
comments && result.comments.push(l.substring(1).trim());
continue;
}
const items = l.trim().split(/\s+/g);
Expand Down
4 changes: 2 additions & 2 deletions packages/hdom-mock/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class MockHDOM implements HDOMImplementation<HDOMNode> {
break;
default:
if (isListener) {
const lid = id.substr(2);
const lid = id.substring(2);
const listeners = el.listeners[lid];
(listeners || (el.listeners[lid] = [])).push(val);
} else {
Expand All @@ -236,7 +236,7 @@ export class MockHDOM implements HDOMImplementation<HDOMNode> {
for (let i = attribs.length; i-- > 0; ) {
const a = attribs[i];
if (a.indexOf("on") === 0) {
const listeners = el.listeners[a.substr(2)];
const listeners = el.listeners[a.substring(2)];
if (listeners) {
const i = listeners.indexOf(prev[a]);
i >= 0 && listeners.splice(i, 1);
Expand Down
Loading

0 comments on commit 0710509

Please sign in to comment.