Skip to content

Commit

Permalink
Pull isULID into the utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph authored and gitbutler-client committed Sep 12, 2024
1 parent 8e28f61 commit 1dafbc8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
15 changes: 1 addition & 14 deletions scripts/ob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ import { basename, dirname, join, extname } from "jsr:@std/path";
import { move } from "jsr:@std/fs";
import { extractYaml } from "jsr:@std/front-matter";
import { contentType } from "jsr:@std/media-types";

// async function write(text: string) {
// const encoder = new TextEncoder();
// const data = encoder.encode(text);

// // Write the data to stdout without a newline
// await Deno.stdout.write(data);
// }

function isULID(str: string) {
// ULID regex to validate the format
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
return ulidRegex.test(str);
}
import { isULID, slugify } from "../src/utils.ts";

const rename = new Command()
.description("Renames a note with a ULID")
Expand Down
8 changes: 2 additions & 6 deletions src/pages/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import { isULID } from "../utils.ts";
export const prerender = false;
/** 1 month in seconds */
Expand All @@ -10,12 +12,6 @@ const CACHE_TTL = 60 * 60 * 24 * 30;
// simpler for now.
const HOME_SLUG = "01J4CPMJ91NF1DNQPE3TZ50HH0";
const ulidRegex = /^[0-9A-HJ-NP-TV-Z]{26}$/i;
function isULID(ulid: string) {
return ulidRegex.test(ulid);
}
/**
* If a `get` KV request returns null and it was requested with a cacheTTL,
* the empty result will be cached. That's usually not what we want, so this
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const slugify = (s: string) =>

export const isValidSha256 = (hashString: string) =>
/^[a-fA-F0-9]{64}$/.test(hashString);

export const isULID = (str: string) => /^[0-9A-HJKMNP-TV-Z]{26}$/i.test(str);

0 comments on commit 1dafbc8

Please sign in to comment.