Skip to content

Commit

Permalink
Node 18+ πŸ’₯; convert to ESM πŸ’₯πŸ“
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Dec 28, 2022
1 parent da308a2 commit 8556afd
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"es2021": true,
"node": true
},
"parserOptions": {
"sourceType": "module"
},
"ignorePatterns": [
"node_modules"
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['10', '12', '14', '16', '18']
node-version: ['18']

steps:
- name: checkout
Expand Down
13 changes: 6 additions & 7 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict'

const createHafas = require('.')
// const createThrottledHafas = require('./throttle')
// const createHafasWithRetry = require('./retry')
import {inspect} from 'node:util'
import {createBvgHafas as createHafas} from './index.js'
// import {createThrottledHafas} from './throttle.js'
// import {createRetryingClient} from './retry.js'

const hafas = createHafas('bvg-hafas-example')
// const hafas = createThrottledHafas('bvg-hafas-example', {
// throttlingLimit: 5,
// throttlingInterval: 10000 // 10s
// })
// const hafas = createHafasWithRetry('bvg-hafas-example', {
// const hafas = createRetryingClient('bvg-hafas-example', {
// retryOpts: {retries: 2}
// })

Expand Down Expand Up @@ -42,7 +41,7 @@ hafas.journeys(spichernstr, bismarckstr, {
// }, {results: 10})

.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.catch((err) => {
console.error(err)
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict'

const createHafasClient = require('hafas-client')
const bvgProfile = require('hafas-client/p/bvg')
import createHafasClient from 'hafas-client'
import bvgProfile from 'hafas-client/p/bvg/index.js'

const defaults = {
profile: bvgProfile
}

const createClient = (userAgent, opt = {}) => {
const createBvgHafas = (userAgent, opt = {}) => {
const {
profile,
} = {...defaults, ...opt}

return createHafasClient(profile, userAgent)
}

createClient.defaults = defaults
module.exports = createClient
export {
defaults,
createBvgHafas,
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "bvg-hafas",
"description": "JavaScript client for the BVG HAFAS API.",
"version": "3.1.0",
"type": "module",
"main": "index.js",
"files": [
"index.js",
Expand All @@ -25,7 +26,7 @@
"bugs": "https://github.com/public-transport/bvg-hafas/issues",
"license": "ISC",
"engines": {
"node": ">=10"
"node": ">=18"
},
"dependencies": {
"hafas-client": "^5.0.1"
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Check [the docs for `hafas-client@5`](https://github.com/public-transport/hafas-
## Usage

```javascript
const createClient = require('bvg-hafas')
import {createBvgHafas} from 'bvg-hafas'

const client = createClient('my-awesome-program')
const client = createBvgHafas('my-awesome-program')
```

As an example, we will search for a route from *Berlin Jungfernheide* to *Tempelhof*. To get the station IDs, use [`locations(query, [opt])`](https://github.com/public-transport/hafas-client/blob/5/docs/locations.md).
Expand Down
12 changes: 6 additions & 6 deletions retry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const createClient = require('hafas-client')
const withRetrying = require('hafas-client/retry')
const bvgProfile = require('hafas-client/p/bvg')
import createClient from 'hafas-client'
import withRetrying from 'hafas-client/retry.js'
import bvgProfile from 'hafas-client/p/bvg/index.js'

const createRetryingClient = (userAgent, opt = {}) => {
const {retryOpts} = {retryOpts: {}, ...opt}
Expand All @@ -11,4 +9,6 @@ const createRetryingClient = (userAgent, opt = {}) => {
return createClient(retryingProfile, userAgent, opt)
}

module.exports = createRetryingClient
export {
createRetryingClient,
}
12 changes: 6 additions & 6 deletions throttle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const createClient = require('hafas-client')
const withThrottling = require('hafas-client/throttle')
const bvgProfile = require('hafas-client/p/bvg')
import createClient from 'hafas-client'
import withThrottling from 'hafas-client/throttle.js'
import bvgProfile from 'hafas-client/p/bvg/index.js'

const createThrottledClient = (userAgent, opt = {}) => {
const {
Expand All @@ -18,4 +16,6 @@ const createThrottledClient = (userAgent, opt = {}) => {
return createClient(throttledProfile, userAgent, opt)
}

module.exports = createThrottledClient
export {
createThrottledClient,
}

0 comments on commit 8556afd

Please sign in to comment.