open source is social v-it.org
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 sol pbc
3
4// Skill ref format: skill-{name}
5// Name: lowercase letters, numbers, hyphens. No leading hyphen, no consecutive hyphens. Max 64 chars.
6
7export const SKILL_NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
8export const SKILL_REF_PATTERN = /^skill-[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
9export const SKILL_NAME_MAX = 64;
10
11export function isValidSkillName(name) {
12 if (!name || typeof name !== 'string') return false;
13 if (name.length > SKILL_NAME_MAX) return false;
14 return SKILL_NAME_PATTERN.test(name);
15}
16
17export function isSkillRef(ref) {
18 if (!ref || typeof ref !== 'string') return false;
19 return ref.startsWith('skill-');
20}
21
22export function skillRefFromName(name) {
23 return `skill-${name}`;
24}
25
26export function nameFromSkillRef(ref) {
27 if (!isSkillRef(ref)) return null;
28 return ref.slice(6);
29}
30
31export function isValidSkillRef(ref) {
32 if (!ref || typeof ref !== 'string') return false;
33 // skill- prefix + valid name, total ref max 71 chars (6 + 64 + 1 for the hyphen in prefix)
34 if (!SKILL_REF_PATTERN.test(ref)) return false;
35 const name = nameFromSkillRef(ref);
36 return name.length <= SKILL_NAME_MAX;
37}