Compare commits

...

4 Commits

Author SHA1 Message Date
a73cd2b923
publish
All checks were successful
Build and publish / publish (push) Successful in 10s
2023-08-26 13:54:19 -07:00
fb45ad6ee5
0.2.0 2023-08-26 13:54:05 -07:00
2527241e25
readme 2023-08-26 13:53:58 -07:00
065a29f0cc
more types 2023-08-26 13:49:57 -07:00
9 changed files with 71 additions and 9 deletions

View File

@ -3,9 +3,9 @@ name: Build and publish
on:
workflow_dispatch: { }
# push:
# branches:
# - master
push:
branches:
- master
jobs:
publish:

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@templates/typescript-types",
"version": "1.0.0",
"version": "0.2.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@templates/typescript-types",
"version": "1.0.0",
"version": "0.2.0",
"license": "ISC",
"devDependencies": {
"typescript": "^5.1.3"

View File

@ -1,7 +1,7 @@
{
"name": "@js/types",
"version": "0.1.0",
"description": "Template project for creating new TypeScript type-definition-only packages",
"version": "0.2.0",
"description": "Collection of generic TypeScript type definitions for various utility purposes",
"main": "src/index.d.ts",
"types": "src/index.d.ts",
"publishConfig": {
@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "https://gitea.jbrumond.me/js/typescript-types.git"
"url": "https://gitea.jbrumond.me/js/types.git"
},
"author": "James Brumond <https://jbrumond.me>",
"license": "ISC",

View File

@ -14,6 +14,7 @@ npm install --save-dev @js/types
import {
// Various identifier strings
HttpURL,
HttpURLSchemeless,
UUID,
SnowflakeID,
@ -24,6 +25,24 @@ import {
// Pino-compatible logger interface
Logger,
LogFn,
} from '@js/types';
// Function helpers
Func,
Params,
FirstParam,
NonFirstParams,
WithoutFirstParam,
// Language / locale
Locale,
// Date / time
ISODate,
ISOTime,
ISOZoneOffset,
ISOTimestamp,
TimeShort,
LocalDateTime,
Timezone,
} from '@js/types';
```

10
src/functions.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
export type Func<T extends any = any> = (...args: any[]) => T;
export type Params<T extends Func> = T extends (...args: infer P) => any ? P : never;
export type FirstParam<T extends Func> = T extends (first: infer F, ...args: any[]) => any ? F : never;
export type NonFirstParams<T extends Func> = T extends (first: any, ...args: infer P) => any ? P : never;
export type WithoutFirstParam<T extends Func> = T extends (first: any, ...args: infer P) => infer R ? (...args: P) => R : never;

View File

@ -1,6 +1,12 @@
/** An HTTP URL, e.g. `https://example.com/foo?bar=baz` */
export type HttpURL = `http://${string}` | `https://${string}`;
/** An HTTP URL without the scheme specified, e.g. `//example.com/foo?bar=baz` */
export type HttpURLSchemeless = `//${string}`;
/** An RFC 4122 Universally Unique Identifier string */
export type UUID = `${string}-${string}-${string}-${string}-${string}`;
/** A Snowflake unique identifier string */
export type SnowflakeID = `${bigint}`;

3
src/index.d.ts vendored
View File

@ -1,4 +1,7 @@
export * from './functions';
export * from './http';
export * from './identifiers';
export * from './locale';
export * from './logger';
export * from './time';

3
src/locale.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
/** A combined ISO 639-1 language code and ISO 3166-1 alpha-2 country code, like `en-US` */
export type Locale = `${string}-${string}`;

21
src/time.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
/** A date string, formatted `YYYY-MM-DD` */
export type ISODate = `${number}-${number}-${number}`;
/** A time string, formatted `HH:mm:ss.sss` */
export type ISOTime = `${number}:${number}:${number}.${number}`;
/** */
export type ISOZoneOffset = 'Z' | `${'+' | '-' | ''}${number}:${number}`;
/** */
export type ISOTimestamp = `${ISODate}T${ISOTime}${ISOZoneOffset}`;
/** A time string, formatted `HH:mm` */
export type TimeShort = `${number}:${number}`;
/** A date/time string, formatted `YYYY-MM-DD HH:mm` */
export type LocalDateTime = `${ISODate} ${TimeShort}`;
/** A timezone identifier string, like `America/Los_Angeles` */
export type Timezone = `${string}/${string}`;