From b97c4a2d37a285adc8564865d72db2dc86b6300e Mon Sep 17 00:00:00 2001 From: mason Date: Sun, 15 Dec 2024 02:24:16 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20try=20to=20fix=20ERR=5FMA?= =?UTF-8?q?SONMARK=5FNOT=5FWRITE=5FENOUGH=5FDOCS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AlphabeticOrUnderscoreOrHyphenString.ts | 4 +++ AlphabeticOrUnderscoreString.ts | 3 +++ AlphabeticString.ts | 4 +++ AwesomeString.ts | 35 ------------------------- LowercaseAlphabeticString.ts | 3 +++ PrometheusMetricName.ts | 2 ++ PrometheusMetricNameWithoutColon.ts | 5 ++++ 7 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 AwesomeString.ts diff --git a/AlphabeticOrUnderscoreOrHyphenString.ts b/AlphabeticOrUnderscoreOrHyphenString.ts index 844a6ae..26cb837 100644 --- a/AlphabeticOrUnderscoreOrHyphenString.ts +++ b/AlphabeticOrUnderscoreOrHyphenString.ts @@ -15,5 +15,9 @@ const JSRCompatibleFactory = ValidatedString.create( const type: ValidatedString = JSRCompatibleFactory.type; const factory: ValidatedStringFactory = JSRCompatibleFactory.factory; + +/** + A string that contains only characters `[a-zA-Z_-]` (letters, underscores, or hyphens). + */ export type AlphabeticOrUnderscoreOrHyphenString = typeof type; export const AlphabeticOrUnderscoreOrHyphenString = factory; diff --git a/AlphabeticOrUnderscoreString.ts b/AlphabeticOrUnderscoreString.ts index 744f4bb..17f115f 100644 --- a/AlphabeticOrUnderscoreString.ts +++ b/AlphabeticOrUnderscoreString.ts @@ -13,5 +13,8 @@ const JSRCompatibleFactory = ValidatedString.create(isAlphabeticOrUnderscore, { const type: ValidatedString = JSRCompatibleFactory.type; const factory: ValidatedStringFactory = JSRCompatibleFactory.factory; +/** + A string that contains only characters `[a-zA-Z_]` (letters or underscores). + */ export type AlphabeticOrUnderscoreString = typeof type; export const AlphabeticOrUnderscoreString = factory; diff --git a/AlphabeticString.ts b/AlphabeticString.ts index 484f945..bc8968a 100644 --- a/AlphabeticString.ts +++ b/AlphabeticString.ts @@ -13,5 +13,9 @@ const JSRCompatibleFactory = ValidatedString.create(isAlphabetic, { const type: ValidatedString = JSRCompatibleFactory.type; const factory: ValidatedStringFactory = JSRCompatibleFactory.factory; + +/** + A string that contains only letters `[a-zA-Z]`. + */ export type AlphabeticString = typeof type; export const AlphabeticString = factory; diff --git a/AwesomeString.ts b/AwesomeString.ts deleted file mode 100644 index 170750e..0000000 --- a/AwesomeString.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ValidatedString, type ValidatedStringFactory } from './ValidatedString.ts'; - -const isAwesome = (s: string): boolean => s === 'awesome'; - -/** - Why JSRCompatibleFactory? See https://github.com/axhxrx/validated-string/issues/1 — consumers of this lib probably don't need to deal with this - */ -const JSRCompatibleFactory = ValidatedString.create(isAwesome); - -const type: ValidatedString = JSRCompatibleFactory.type; -const factory: ValidatedStringFactory = JSRCompatibleFactory.factory; - -export type AwesomeString = typeof type; -export const AwesomeString = factory; - -// Usage: -const x = AwesomeString.try('awesome'); // AwesomeString | undefined -const y: AwesomeString = AwesomeString.assert('awesome'); // AwesomeString - -// If invalid: -const z = AwesomeString.try('not awesome'); // undefined - -console.log('x is ', x); -console.log('y is ', y); -console.log('z is ', z); - -try -{ - const ohno = AwesomeString.assert('not awesome'); - console.log('ohno is ', ohno); -} -catch (error) -{ - console.log('Got error as expected:', error); -} diff --git a/LowercaseAlphabeticString.ts b/LowercaseAlphabeticString.ts index c6cc18d..a85b15a 100644 --- a/LowercaseAlphabeticString.ts +++ b/LowercaseAlphabeticString.ts @@ -13,5 +13,8 @@ const JSRCompatibleFactory = ValidatedString.create(isLowercaseAlpha, { const type: ValidatedString = JSRCompatibleFactory.type; const factory: ValidatedStringFactory = JSRCompatibleFactory.factory; +/** + A string that contains only lowercase letters `[a-z]`. + */ export type LowercaseAlphabeticString = typeof type; export const LowercaseAlphabeticString = factory; diff --git a/PrometheusMetricName.ts b/PrometheusMetricName.ts index 156baf4..3c841b3 100644 --- a/PrometheusMetricName.ts +++ b/PrometheusMetricName.ts @@ -15,6 +15,8 @@ const factory: ValidatedStringFactory = JSRCompat /** A validated string that represents a Prometheus metric name. See {@link ValidatedString} for more information. Note that this might not really exactly match the rules for Prometheus metric names, but it's close enough for our purposes; namely, generating metrics — don't rely on this to *validate* Prometheus metric names, as it is based on a quick skim of the Prometheus docs. + + @category Prometheus */ export type PrometheusMetricName = typeof type; export const PrometheusMetricName = factory; diff --git a/PrometheusMetricNameWithoutColon.ts b/PrometheusMetricNameWithoutColon.ts index 1686b75..54c384b 100644 --- a/PrometheusMetricNameWithoutColon.ts +++ b/PrometheusMetricNameWithoutColon.ts @@ -17,5 +17,10 @@ const JSRCompatibleFactory = ValidatedString.create( const type: ValidatedString = JSRCompatibleFactory.type; const factory: ValidatedStringFactory = JSRCompatibleFactory.factory; +/** + A validated string that represents a Prometheus metric name, but without the colon. See {@link ValidatedString} and {@link PrometheusMetricName} for more information. + + @category Prometheus + */ export type PrometheusMetricNameWithoutColon = typeof type; export const PrometheusMetricNameWithoutColon = factory;