app/lib/editor/duplicate.mjs
25 lines and 2 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| baseOf | 8 to 12 | 2 | 100% | OkCRAP 2 | No data: no mutants in this code |
| copySlugCandidates | 19 to 26 | 2 | 100% | OkCRAP 2 | No data: no mutants in this code |
Imports
It imports no other module of this repo. Imported by app/lib/admin/posts-actions.server.ts.
Source
/**
* Strips a trailing -copy or -copy-<n> so duplicating a duplicate stays flat (a-post-copy-2, not
* a-post-copy-copy). A slug genuinely ending in -copy collides; accepted, since the rule is textual.
*
* @param {string} slug
* @returns {string}
*/
function baseOf(slug) {
const stripped = slug.replace(/-copy(?:-\d+)?$/, "");
// A slug that is only the suffix would leave candidates starting with a hyphen.
return stripped === "" ? slug : stripped;
}
/**
* @param {string} slug
* @param {number} [limit]
* @returns {string[]}
*/
export function copySlugCandidates(slug, limit = 20) {
const base = baseOf(slug);
/** @type {string[]} */
const out = [`${base}-copy`];
// Starts at 2: the unnumbered candidate is the first copy.
for (let n = 2; out.length < limit; n += 1) out.push(`${base}-copy-${n}`);
return out;
}