Skip to content

Commit

Permalink
Merge pull request #12 from bjuppa/enable-tree-shaking
Browse files Browse the repository at this point in the history
Remove type-lift
  • Loading branch information
bjuppa authored May 22, 2023
2 parents af83617 + 9e29f23 commit 179873d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 9 deletions.
41 changes: 41 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Development

```sh
# Run tests
deno test

# Linter
deno lint

# Formatter
deno fmt --check
deno fmt
```

## Releases

Releases are to be created and managed through
[GitHub Releases](https://github.com/bjuppa/com-plain-date/releases).

New releases are automatically published to
[deno.land](https://deno.land/x/complaindate) with a
[GitHub Webhook](https://github.com/bjuppa/com-plain-date/settings/hooks) and to
[npm](https://www.npmjs.com/package/complaindate) with a
[GitHub Action](https://github.com/bjuppa/com-plain-date/actions).

## Testing the package

There's a script (using [dnt](https://github.com/denoland/dnt)) that generates
an npm package from the current code into [the `npm/` directory](/npm):

```sh
# Version tag is not required for local testing
deno run -A scripts/build_npm.ts
```

If you have an npm project setup locally for testing, you may install the built
package using a local path:

```sh
npm install path/to/com-plain-date/npm
```
1 change: 0 additions & 1 deletion ExPlainDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,4 @@ export function ExPlainDate(
return exPlainDate;
}

ExPlainDate.of = ExPlainDate;
ExPlainDate.fromString = PlainDate.fromString;
6 changes: 1 addition & 5 deletions PlainDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export interface ComPlainDate {
/** Describes a factory function that creates plain-date objects */
export interface PlainDateFactory<T extends ComPlainDate> {
(x: SloppyDate): T;
/** Type lift (unit) */
of: PlainDateFactory<T>;
/** Create a new plain-date object from an ISO string */
fromString: <T extends ComPlainDate>(
this: PlainDateFactory<T>,
Expand Down Expand Up @@ -178,8 +176,6 @@ export function PlainDate(
return plainDate;
}

PlainDate.of = PlainDate;

PlainDate.fromString = function <T extends ComPlainDate>(
this: PlainDateFactory<T>,
isoDateString: string,
Expand All @@ -188,5 +184,5 @@ PlainDate.fromString = function <T extends ComPlainDate>(
if (!parts) {
throw TypeError(`No date parts found in string: ${isoDateString}`);
}
return this.of(parts);
return this(parts);
};
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ available — only time will tell...

[API documentation at deno.land](https://deno.land/x/complaindate/mod.ts)

The footprint of a tree-shaken and compressed production build starts below
`1.5 kB` when using just the `PlainDate` object API.

## Quick example

```ts
Expand Down
18 changes: 18 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"lock": false,
"lint": {
"exclude": [
"npm/"
]
},
"fmt": {
"exclude": [
"npm/"
]
},
"test": {
"exclude": [
"npm/"
]
}
}
2 changes: 1 addition & 1 deletion utils/splitDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function splitDateTime(timezone: string) {
instant ??= new Date();
const locale = "en";
const options = { timeZone: timezone, hour12: false };
const plainDate = PlainDate.of({
const plainDate = PlainDate({
year: instant.toLocaleDateString(locale, { ...options, year: "numeric" }),
month: instant.toLocaleDateString(locale, {
...options,
Expand Down
2 changes: 1 addition & 1 deletion utils/splitLocalDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SplitDateTime } from "../support/date-time-types.ts";
*/
export function splitLocalDateTime(instant?: Date): SplitDateTime {
instant ??= new Date();
const plainDate = PlainDate.of({
const plainDate = PlainDate({
year: instant.getFullYear(),
month: instant.getMonth() + 1,
day: instant.getDate(),
Expand Down
2 changes: 1 addition & 1 deletion utils/splitUtcDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SplitDateTime } from "../support/date-time-types.ts";
*/
export function splitUtcDateTime(instant?: Date): SplitDateTime {
instant ??= new Date();
const plainDate = PlainDate.of({
const plainDate = PlainDate({
year: instant.getUTCFullYear(),
month: instant.getUTCMonth() + 1,
day: instant.getUTCDate(),
Expand Down

0 comments on commit 179873d

Please sign in to comment.