Skip to content

Commit

Permalink
🔧 fix: use explicit return types
Browse files Browse the repository at this point in the history
  • Loading branch information
masonmark committed Dec 14, 2024
1 parent 6d53983 commit ebf100b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
12 changes: 7 additions & 5 deletions AlphabeticOrUnderscoreOrHyphenString.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ValidatedString } from './ValidatedString.ts';

const isAlphabeticOrUnderscoreOrHyphen = (s: string) => /^[a-zA-Z_-]+$/.test(s);

const { factory, type } = ValidatedString.create(isAlphabeticOrUnderscoreOrHyphen, {
name: 'AlphabeticOrUnderscoreOrHyphenString',
description: 'must contain only letters (A-Z, a-z), underscores, or hyphens',
});
const { factory, type } = ValidatedString.create(
isAlphabeticOrUnderscoreOrHyphen,
{
name: 'AlphabeticOrUnderscoreOrHyphenString',
description: 'must contain only letters (A-Z, a-z), underscores, or hyphens',
},
);

export type AlphabeticOrUnderscoreOrHyphenString = typeof type;
export const AlphabeticOrUnderscoreOrHyphenString = factory;
2 changes: 1 addition & 1 deletion AlphabeticOrUnderscoreString.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidatedString } from './ValidatedString.ts';

const isAlphabeticOrUnderscore = (s: string) => /^[a-zA-Z_]+$/.test(s);
const isAlphabeticOrUnderscore = (s: string): boolean => /^[a-zA-Z_]+$/.test(s);

const { factory, type } = ValidatedString.create(isAlphabeticOrUnderscore, {
name: 'AlphabeticOrUnderscoreString',
Expand Down
2 changes: 1 addition & 1 deletion AlphabeticString.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidatedString } from './ValidatedString.ts';

const isAlphabetic = (s: string) => /^[a-zA-Z]+$/.test(s);
const isAlphabetic = (s: string): boolean => /^[a-zA-Z]+$/.test(s);

const { factory, type } = ValidatedString.create(isAlphabetic, {
name: 'AlphabeticString',
Expand Down
2 changes: 1 addition & 1 deletion AwesomeString.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidatedString } from './ValidatedString.ts';

const isAwesome = (s: string) => s === 'awesome';
const isAwesome = (s: string): boolean => s === 'awesome';

const { factory, type } = ValidatedString.create(isAwesome);
export type AwesomeString = typeof type;
Expand Down
2 changes: 1 addition & 1 deletion LowercaseAlphabeticString.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidatedString } from './ValidatedString.ts';

const isLowercaseAlpha = (s: string) => /^[a-z]+$/.test(s);
const isLowercaseAlpha = (s: string): boolean => /^[a-z]+$/.test(s);

const { factory, type } = ValidatedString.create(isLowercaseAlpha, {
name: 'LowercaseAlphabeticString',
Expand Down
2 changes: 1 addition & 1 deletion PrometheusMetricName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidatedString } from './ValidatedString.ts';

const isPrometheusMetricName = (s: string) => /^[a-zA-Z_:][a-zA-Z0-9_:]*$/.test(s);
const isPrometheusMetricName = (s: string): boolean => /^[a-zA-Z_:][a-zA-Z0-9_:]*$/.test(s);

const { factory, type } = ValidatedString.create(isPrometheusMetricName, {
name: 'PrometheusMetricName',
Expand Down
13 changes: 8 additions & 5 deletions PrometheusMetricNameWithoutColon.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ValidatedString } from './ValidatedString.ts';

const isPrometheusMetricNameWithoutColon = (s: string) => /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s);
const isPrometheusMetricNameWithoutColon = (s: string): boolean => /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s);

const { factory, type } = ValidatedString.create(isPrometheusMetricNameWithoutColon, {
name: 'PrometheusMetricNameWithoutColon',
description: 'must start with a letter or underscore, followed by letters, digits, or underscores',
});
const { factory, type } = ValidatedString.create(
isPrometheusMetricNameWithoutColon,
{
name: 'PrometheusMetricNameWithoutColon',
description: 'must start with a letter or underscore, followed by letters, digits, or underscores',
},
);

export type PrometheusMetricNameWithoutColon = typeof type;
export const PrometheusMetricNameWithoutColon = factory;

0 comments on commit ebf100b

Please sign in to comment.