Skip to content

Commit

Permalink
feat(hooks): GetFormatHook
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Mar 4, 2023
1 parent 87a2292 commit 1d9dd7c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/hooks/__tests__/get-format.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file Type Tests - GetFormatHook
* @module esm-types/hooks/tests/unit-d/GetFormatHook
*/

import type { ResolvedModuleUrl } from '#src/types'
import type TestSubject from '../get-format'
import type GetFormatHookContext from '../get-format-context'
import type GetFormatHookResult from '../get-format-result'

describe('unit-d:hooks/GetFormatHook', () => {
it('should be callable with [ResolvedModuleUrl, GetFormatHookContext, GetFormatHook]', () => {
// Arrange
type Expected = [
url: ResolvedModuleUrl,
context: GetFormatHookContext,
defaultGetFormat: TestSubject
]

// Expect
expectTypeOf<TestSubject>().parameters.toEqualTypeOf<Expected>()
})

it('should return Promise<GetFormatHookResult>', () => {
// Arrange
type Expected = Promise<GetFormatHookResult>

// Expect
expectTypeOf<TestSubject>().returns.toEqualTypeOf<Expected>()
})
})
34 changes: 34 additions & 0 deletions src/hooks/get-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file Hooks - GetFormatHook
* @module esm-types/hooks/GetFormatHook
*/

import type { ResolvedModuleUrl } from '#src/types'
import type GetFormatHookContext from './get-format-context'
import type GetFormatHookResult from './get-format-result'

/**
* Determines how the given module `url` should be interpreted.
*
* The `format` returned also affects what the acceptable forms of source values
* are for a module when parsing.
*
* @see {@linkcode GetFormatHookContext}
* @see {@linkcode GetFormatHookResult}
* @see {@linkcode ResolvedModuleUrl}
* @see https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_getformat_url_context_defaultgetformat
*
* @async
*
* @param {ResolvedModuleUrl} url - Resolved module URL
* @param {GetFormatHookContext} context - Hook context
* @param {GetFormatHook} defaultGetFormat - Default Node.js hook
* @return {Promise<GetFormatHookResult>} Hook result
*/
type GetFormatHook = (
url: ResolvedModuleUrl,
context: GetFormatHookContext,
defaultGetFormat: GetFormatHook
) => Promise<GetFormatHookResult>

export type { GetFormatHook as default }
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* @module esm-types/hooks
*/

export type { default as GetFormatHook } from './get-format'
export type { default as GetFormatHookContext } from './get-format-context'
export type { default as GetFormatHookResult } from './get-format-result'

0 comments on commit 1d9dd7c

Please sign in to comment.