Skip to content

Commit

Permalink
fix: Create separate TypeScript typings for every dist module
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Oct 7, 2018
1 parent a7b5a0b commit 3482934
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 106 deletions.
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Load the main module in the browser with plain JavaScript:
</script>
```

You can also load a specific version from CDN, for example: https://unpkg.com/[email protected].2/dist/index.umd.js.
You can also load a specific version from CDN, for example: https://unpkg.com/[email protected].3/dist/index.umd.js.

## Modules

Expand Down
6 changes: 3 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ Data for 2012-2022: 27 KB minified, 6.5 KB gzipped
Custom time zone data can be used if the module `lookup-convert` is loaded instead of the default `index` module.

```html
<script src="https://unpkg.com/[email protected].2/dist/lookup-convert.umd.js"></script>
<script src="https://unpkg.com/[email protected].2/dist/data-2012-2022.umd.js"></script>
<script src="https://unpkg.com/[email protected].3/dist/lookup-convert.umd.js"></script>
<script src="https://unpkg.com/[email protected].3/dist/data-2012-2022.umd.js"></script>
<script>
(() => {
const { populateTimeZones, findTimeZone, getZonedTime } = window['timezone-lookup-convert']
Expand All @@ -199,7 +199,7 @@ Custom time zone data can be used if the module `lookup-convert` is loaded inste
If you want to use the time zone data for years 2012-2022 published by this project, you can simplify your code by using a bundled package with both data and code.

```html
<script src="https://unpkg.com/[email protected].2/dist/index-2012-2022.umd.js"></script>
<script src="https://unpkg.com/[email protected].3/dist/index-2012-2022.umd.js"></script>
<script>
(() => {
const { findTimeZone, getZonedTime } = window['timezone-support']
Expand Down
95 changes: 0 additions & 95 deletions index.d.ts

This file was deleted.

141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"node": ">=6"
},
"main": "dist/index.js",
"types": "index.d.ts",
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"prepare": "npm run build",
"lint": "run-s lint:js lint:ts",
Expand All @@ -35,7 +39,8 @@
"generate": "node util/wrap-data && node util/wrap-limited-data",
"generate:browser-tests": "node util/generate-browser-tests",
"compile": "rollup -c",
"build": "run-s lint generate compile",
"copy:typings": "cpy src/*.d.ts dist && cpy src/lookup/*.d.ts dist",
"build": "run-s lint generate compile copy:typings",
"compile:tests": "tsc --lib es6 test/typings.test.ts",
"check": "jest --testPathIgnorePatterns \"browser.test.js\" --collectCoverage",
"check:browser": "jest --testPathPattern browser.test.js",
Expand All @@ -51,11 +56,6 @@
"src/lookup/data.js"
]
},
"files": [
"dist",
"src",
"index.d.ts"
],
"jest": {
"roots": [
"test"
Expand Down Expand Up @@ -83,6 +83,7 @@
"benchmark": "^2.1.4",
"connect": "^3.6.6",
"coveralls": "^3.0.2",
"cpy-cli": "^2.0.0",
"es6-promisify": "^6.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
Expand Down
44 changes: 44 additions & 0 deletions src/index-2012-2022.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
type DateInput = Date | number

interface TimeZoneInfo {
name: string
}

interface TimeZoneOffset {
abbreviation?: string
offset: number
}

interface Time {
year: number
month: number
day: number
hours: number
minutes: number
seconds?: number
milliseconds?: number
dayOfWeek?: number
epoch?: number
zone?: TimeZoneOffset
}

interface SetTimeZoneOptions {
useUTC: boolean
}

declare function listTimeZones (): Array<string>
declare function findTimeZone (name: string): TimeZoneInfo

declare function getUTCOffset (date: DateInput, timeZone: TimeZoneInfo): TimeZoneOffset
declare function getZonedTime (date: DateInput, timeZone: TimeZoneInfo): Time
declare function getUnixTime (time: Time, timeZone?: TimeZoneInfo): number
declare function setTimeZone (time: Date | Time, timeZone: TimeZoneInfo, options?: SetTimeZoneOptions): Time

declare function convertTimeToDate (time: Time): Date
declare function convertDateToTime (date: Date): Time

export {
listTimeZones, findTimeZone, getUTCOffset, getZonedTime, getUnixTime, setTimeZone, convertTimeToDate, convertDateToTime
}

// export as namespace timezoneSupport;
Loading

0 comments on commit 3482934

Please sign in to comment.