Refactor: Move 11ty filters to separate file

This commit is contained in:
Lea Verou
2024-12-17 12:08:41 -05:00
parent 9c4e4a2280
commit 1bf83499b0
2 changed files with 29 additions and 13 deletions

24
docs/_utils/filters.js Normal file
View File

@@ -0,0 +1,24 @@
import { parse } from 'path';
export function stripExtension(string) {
return parse(string).name;
}
export function stripPrefix(content) {
return content.replace(/^wa-/, '');
}
// Trims whitespace and pipes from the start and end of a string. Useful for CEM types, which can be pipe-delimited.
// With Prettier 3, this means a leading pipe will exist be present when the line wraps.
export function trimPipes(content) {
return typeof content === 'string' ? content.replace(/^(\s|\|)/g, '').replace(/(\s|\|)$/g, '') : content;
}
export function keys(obj) {
return Object.keys(obj);
}
export function log(firstArg, ...rest) {
console.log(firstArg, ...rest);
return firstArg;
}