Skip to content

Commit

Permalink
fix: tend a falsy opts.cb
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Mar 19, 2021
1 parent 27f2518 commit 8626c30
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 26 deletions.
@@ -1 +1 @@
{"total":{"lines":{"total":219,"covered":219,"skipped":0,"pct":100},"statements":{"total":233,"covered":233,"skipped":0,"pct":100},"functions":{"total":26,"covered":26,"skipped":0,"pct":100},"branches":{"total":308,"covered":308,"skipped":0,"pct":100}}}
{"total":{"lines":{"total":218,"covered":218,"skipped":0,"pct":100},"statements":{"total":234,"covered":234,"skipped":0,"pct":100},"functions":{"total":26,"covered":26,"skipped":0,"pct":100},"branches":{"total":309,"covered":309,"skipped":0,"pct":100}}}
Expand Up @@ -551,7 +551,12 @@ function fixEnt(str, originalOpts) {
return rangesArr2.every(function (oneOfEveryObj, y) {
return i === y || !(filteredRangeObj.rangeFrom >= oneOfEveryObj.rangeFrom && filteredRangeObj.rangeTo < oneOfEveryObj.rangeTo);
});
}).map(opts.cb);
});
/* istanbul ignore else */
if (typeof opts.cb === "function") {
return res.map(opts.cb);
}
/* istanbul ignore next */
return res;
}

Expand Down
Expand Up @@ -10719,7 +10719,14 @@ function fixEnt(str, originalOpts) { //
return rangesArr2.every(function (oneOfEveryObj, y) {
return i === y || !(filteredRangeObj.rangeFrom >= oneOfEveryObj.rangeFrom && filteredRangeObj.rangeTo < oneOfEveryObj.rangeTo);
});
}).map(opts.cb);
});
/* istanbul ignore else */

if (typeof opts.cb === "function") {
return res.map(opts.cb);
}
/* istanbul ignore next */

return res;
}

Expand Down
Expand Up @@ -514,11 +514,12 @@ function fixEnt(str, originalOpts) {
if (!rangesArr2.length) {
return [];
}
const res = rangesArr2.filter((filteredRangeObj, i) => {
return rangesArr2.every((oneOfEveryObj, y) => {
return i === y || !(filteredRangeObj.rangeFrom >= oneOfEveryObj.rangeFrom && filteredRangeObj.rangeTo < oneOfEveryObj.rangeTo);
});
}).map(opts.cb);
const res = rangesArr2.filter((filteredRangeObj, i) => rangesArr2.every((oneOfEveryObj, y) => i === y || !(filteredRangeObj.rangeFrom >= oneOfEveryObj.rangeFrom && filteredRangeObj.rangeTo < oneOfEveryObj.rangeTo)));
/* istanbul ignore else */
if (typeof opts.cb === "function") {
return res.map(opts.cb);
}
/* istanbul ignore next */
return res;
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

34 changes: 19 additions & 15 deletions packages/string-fix-broken-named-entities/src/main.ts
Expand Up @@ -35,7 +35,7 @@ interface cbObj {
}
interface Opts {
decode: boolean;
cb: (obj: cbObj) => void;
cb: null | ((obj: cbObj) => void);
entityCatcherCb: null | ((from: number, to: number) => void);
textAmpersandCatcherCb: null | ((idx: number) => void);
progressFn: null | ((percDone: number) => void);
Expand Down Expand Up @@ -1506,27 +1506,31 @@ function fixEnt(str: string, originalOpts?: Partial<Opts>): Ranges {
// "rangeValDecoded": "&"
// },
// so instead of [4, 8] that would be [rangeFrom, rangeTo]...
const res: any = rangesArr2
.filter((filteredRangeObj, i) => {
return rangesArr2.every((oneOfEveryObj, y) => {
return (
i === y ||
!(
filteredRangeObj.rangeFrom >= oneOfEveryObj.rangeFrom &&
filteredRangeObj.rangeTo < oneOfEveryObj.rangeTo
)
);
});
})
.map(opts.cb);
const res: any = rangesArr2.filter((filteredRangeObj, i) =>
rangesArr2.every(
(oneOfEveryObj, y) =>
i === y ||
!(
filteredRangeObj.rangeFrom >= oneOfEveryObj.rangeFrom &&
filteredRangeObj.rangeTo < oneOfEveryObj.rangeTo
)
)
);

/* istanbul ignore else */
if (typeof opts.cb === "function") {
console.log(`1522 ${`\u001b[${32}m${`RETURN`}\u001b[${39}m`} mapped`);
return res.map(opts.cb);
}

console.log(
`1524 RETURN ${`\u001b[${33}m${`res`}\u001b[${39}m`} = ${JSON.stringify(
`1527 RETURN ${`\u001b[${33}m${`res`}\u001b[${39}m`} = ${JSON.stringify(
res,
null,
4
)}`
);
/* istanbul ignore next */
return res;
}

Expand Down
24 changes: 24 additions & 0 deletions packages/string-fix-broken-named-entities/test/throws.js
Expand Up @@ -91,3 +91,27 @@ tap.test(
t.end();
}
);

tap.test(`07 - all callbacks are undefined`, (t) => {
t.doesNotThrow(() => {
fix("", {
cb: undefined,
entityCatcherCb: undefined,
textAmpersandCatcherCb: undefined,
progressFn: undefined,
});
}, "07");
t.end();
});

tap.test(`08 - all callbacks are nulls`, (t) => {
t.doesNotThrow(() => {
fix("", {
cb: null,
entityCatcherCb: null,
textAmpersandCatcherCb: null,
progressFn: null,
});
}, "08");
t.end();
});
2 changes: 1 addition & 1 deletion packages/string-fix-broken-named-entities/types/index.d.ts
Expand Up @@ -13,7 +13,7 @@ interface cbObj {
}
interface Opts {
decode: boolean;
cb: (obj: cbObj) => void;
cb: null | ((obj: cbObj) => void);
entityCatcherCb: null | ((from: number, to: number) => void);
textAmpersandCatcherCb: null | ((idx: number) => void);
progressFn: null | ((percDone: number) => void);
Expand Down

0 comments on commit 8626c30

Please sign in to comment.