diff --git a/package-lock.json b/package-lock.json index ca8d2ae..57c5d6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,21 @@ { "name": "@slawek/sk-tools", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@slawek/sk-tools", - "version": "0.1.0", + "version": "0.1.2", "license": "MIT", "dependencies": { "d3-dsv": "^3.0.1", - "jmespath": "^0.16.0" + "jmespath": "^0.16.0", + "semver": "^7.7.4", + "uuid": "^11.1.0" + }, + "bin": { + "sk-tools": "dist/cli.js" }, "devDependencies": { "@types/d3-dsv": "^3.0.7", @@ -113,6 +118,18 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", @@ -133,6 +150,19 @@ "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", "dev": true, "license": "MIT" + }, + "node_modules/uuid": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz", + "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/esm/bin/uuid" + } } } } diff --git a/package.json b/package.json index 0ec5326..76038b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@slawek/sk-tools", - "version": "0.1.2", + "version": "0.1.3", "type": "module", "files": [ "dist", @@ -10,8 +10,7 @@ "scripts": { "clean": "rm -rf dist", "build": "npm run clean && tsc && chmod +x dist/cli.js", - "build:watch": "tsc --watch", - "prepublishOnly": "npm run build" + "build:watch": "tsc --watch" }, "engines": { "node": ">=24.0.0" @@ -19,7 +18,9 @@ "description": "A set of generic NodeJS utilities shared by Slawek tools.", "dependencies": { "d3-dsv": "^3.0.1", - "jmespath": "^0.16.0" + "jmespath": "^0.16.0", + "semver": "^7.7.4", + "uuid": "^11.1.0" }, "devDependencies": { "@types/d3-dsv": "^3.0.7", diff --git a/src/index.ts b/src/index.ts index 8ccdcd1..343a5f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,3 +9,4 @@ export { readCsvFromStdin, renderOutput, } from "./cli/utils.ts"; +export { getConfig } from "./config/index.ts"; diff --git a/src/markdown.ts b/src/markdown.ts index 0efc833..5faacf0 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -1,5 +1,7 @@ // SPDX-License-Identifier: MIT +import { validate as validateUuid } from "uuid"; + type Scalar = string | number | boolean | null | undefined; type ScalarRow = Record; @@ -20,7 +22,7 @@ function formatCell(value: unknown): string { } const inlineCodePredicates = [ - (value: Scalar): boolean => isGuid(value), + (value: Scalar): boolean => typeof value === "string" && validateUuid(value), (value: Scalar): boolean => typeof value === "string" && /^(?:\d{1,3}\.){3}\d{1,3}(?:\/(?:\d{1,2}|(?:\d{1,3}\.){3}\d{1,3}))?$/.test(value), @@ -38,11 +40,6 @@ function renderCell(raw: Scalar, shouldQuote: boolean): string { return text; } -function isGuid(value: unknown): value is string { - return typeof value === "string" - && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value); -} - function toAutoHeaderLabel(key: string): string { const withSpaces = String(key) .replace(/[_-]+/g, " ")