Skip to content

Commit

Permalink
Adds Typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Jul 11, 2023
1 parent a9f7ac2 commit 7400b27
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ coverage
coverage.info
test/fixtures/*/build
node_modules
lib
!lib/*.d.ts
lib/*.map
lib/*.cjs
lib/*.js
52 changes: 52 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Plugin } from 'metalsmith';
export default initializeInPlace;
export type Render = (source: string, options: any, locals: any) => string;
export type RenderAsync = (source: string, options: any, locals: any, callback: Function) => Promise<string>;
export type Compile = (source: string, options: any) => string;
export type CompileAsync = (source: string, options: any, callback: Function) => Promise<string>;
export type JsTransformer = {
name: string;
inputFormats: string[];
outputFormat: string;
render?: Render;
renderAsync?: RenderAsync;
compile?: Compile;
compileAsync?: CompileAsync;
[key]?: string;
};
export type Options = {
/**
* Jstransformer to run: name of a node module or local JS module path (starting with `.`) whose default export is a jstransformer. As a shorthand for existing transformers you can remove the `jstransformer-` prefix: `marked` will be understood as `jstransformer-marked`. Or an actual jstransformer; an object with `name`, `inputFormats`,`outputFormat`, and at least one of the render methods `render`, `renderAsync`, `compile` or `compileAsync` described in the [jstransformer API docs](https://github.com/jstransformers/jstransformer#api)
*/
transform: string | JsTransformer;
/**
* One or more paths or glob patterns to limit the scope of the transform.
* @default '**\/*.<transform.inputFormats>'
*/
pattern?: string|string[];
/**
* Pass options to the jstransformer templating engine that's rendering your files.
* @default {}
*/
engineOptions?: any;
};
/**
* A metalsmith plugin for in-place templating
* @example
* import nunjucks from 'jstransformer-nunjucks'
*
* metalsmith
* .use(inPlace({ transform: 'jstransformer-nunjucks' })) // use jstransformer-nunjucks
* .use(inPlace({ transform: 'nunjucks' })) // shorthand for above
* .use(inPlace({ transform: nunjucks })) // equivalent to above
* .use(inPlace({ transform: './local/transform.js' })) // custom local transformer
* .use(inPlace({ transform: { // custom inline transformer
* name: 'prepend-hello',
* inputFormats: ['prepend-hello'],
* outputFormat: 'html',
* render(str, options, locals) => {
* return 'hello ' + str
* }
* }}))
*/
declare function initializeInPlace(options?: Options): Plugin;
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ function validate({ filename, files, transform }) {

/**
* @typedef {Object} Options
* @property {string|JsTransformer} transform Jstransformer to run
* @property {string} [pattern='**'] (*optional*) Limit the files to process by 1 or more glob patterns. Defaults to `'**'` (all)
* @property {string|JsTransformer} transform Jstransformer to run: name of a node module or local JS module path (starting with `.`) whose default export is a jstransformer. As a shorthand for existing transformers you can remove the `jstransformer-` prefix: `marked` will be understood as `jstransformer-marked`. Or an actual jstransformer; an object with `name`, `inputFormats`,`outputFormat`, and at least one of the render methods `render`, `renderAsync`, `compile` or `compileAsync` described in the [jstransformer API docs](https://github.com/jstransformers/jstransformer#api)
* @property {string} [pattern='**\/*.<transform.inputFormats>'] (*optional*) One or more paths or glob patterns to limit the scope of the transform. Defaults to `'**\/*.<transform.inputFormats>'`
* @property {Object} [engineOptions={}] (*optional*) Pass options to the jstransformer templating engine that's rendering your files. The default is `{}`
**/

Expand Down

0 comments on commit 7400b27

Please sign in to comment.