Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-extension-hooks

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-extension-hooks - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

changelog.md

13

package.json
{
"name": "require-extension-hooks",
"version": "0.2.0",
"version": "0.3.0",
"description": "Add hooks for js extension types",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "ava"
},
"ava": {
"files": "spec/**/*.spec.js"
},
"repository": {

@@ -22,4 +25,8 @@ "type": "git",

"merge-source-map": "^1.0.3",
"minimatch": "^3.0.4",
"source-map": "^0.5.6"
},
"devDependencies": {
"ava": "^0.20.0"
}
}

@@ -39,4 +39,22 @@ # require-extension-hooks

Loads a plugin. The plugin can either be a partial name (i.e. for *require-extension-hooks-vue* you can just type `hook.plugin('vue')`), the full name of a plugin (i.e. `hook.plugin('require-extension-hooks-vue')`) or a direct function (i.e. `hook.plugin(function(config){}`).
The plugin function does not automatically append the plugin to the hook queue, you also need to tell it what to do. i.e. `hook.plugin('vue').push()`.
The plugin is automatically added to the hook queue. You can move it to the start of the queue by calling `hook.plugin('xxx').unshift()`.
### include(pattern | fn)
Restricts the hook to only run based on the provided pattern. The argument can either a function (that takes the same configuration options as the hook itself), or a **glob** pattern that is matched against the filename.
```js
// these 2 examples will both only run for files in the node_modules folder
hooks('js').include('**/node_modules/**/*.js').push(...);
hooks('js').include(({filename}) => filename.includes('node_modules'));
```
### exclude(pattern | fn)
Restricts the hook to skip files that do not match the provided pattern. The argument can either a function (that takes the same configuration options as the hook itself), or a **glob** pattern that is matched against the filename.
```js
// these 2 examples will both EXCLUDE any files from the node_modules folder
hooks('js').exclude('**/node_modules/**/*.js').push(...);
hooks('js').exclude(({filename}) => filename.includes('node_modules'));
```
It is possible to chain multiple include and exclude patterns, the file must match all of the patterns to continue.
### config

@@ -56,3 +74,19 @@ A hook function takes a config object as its only argument. This object contains the following options:

The source map object from any previous transpilations. You don't need to manually merge the input source map into your current source map as this is automatically calculated.
#### hook
The `hook` method allows you to parse a file's content through another extension and return the transpiled content. This is useful if you have a file that contains multiple languages.
```js
hooks('.custom').push(function ({content, hook}) {
let {javascriptPart, typescriptPart} = extractStuffFromContent(content);
let transpiledTypescriptPart = hook('.ts', typescriptPart);
return `${javascriptPart}\n${typescriptPart}`;
})
```
The hook method takes a file extension as its first parameter. The second parameter can be one of the following:
- `String` - assumed to be the content you want to parse.
- `{content : String}` - same as passing content directly
- `{content : String, filename : String}` - passes the content to the hook but with a custom filename
- `{filename : String}` - pass in a custom filename and it will read in and transpile that file's content.
If you do not pass any parameters into the `hook` method, it will pass in the current content and filename.
#### return

@@ -59,0 +93,0 @@ The hook function *must* return a value. If no value is returned, the next hook is automatically called instead.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc