Skip to content

Commit

Permalink
changed the project name as recma-mdx-escape-missing-components
Browse files Browse the repository at this point in the history
  • Loading branch information
“talatkuyuk” committed Feb 5, 2024
1 parent d7904c9 commit 55925ac
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# recma-escape-missing-components
# recma-mdx-escape-missing-components

[![NPM version][npm-image]][npm-url]
[![Build][github-build]][github-build-url]
Expand All @@ -13,20 +13,20 @@ It is compatible with [MDX][MDX] version 3.

## When should I use this?

**This plugin is useful if you want to escape the components you did not provide in MDX.** You don't receive an error for missing / not provided components since the `recma-escape-missing-components` sets the default value `() => null` for the components.
**This plugin is useful if you want to escape the components you did not provide in MDX.** You don't receive an error for missing / not provided components since the `recma-mdx-escape-missing-components` sets the default value `() => null` for the components.

## Installation

This package is suitable for ESM only. In Node.js (version 16+), install with npm:

```bash
npm install recma-escape-missing-components
npm install recma-mdx-escape-missing-components
```

or

```bash
yarn add recma-escape-missing-components
yarn add recma-mdx-escape-missing-components
```

## Usage
Expand All @@ -46,15 +46,15 @@ And our module, `example.js`, looks as follows:
```javascript
import { read } from "to-vfile";
import { compile } from "@mdx-js/mdx";
import recmaEscapeMissingComponents from "recma-escape-missing-components";
import recmaMdxEscapeMissingComponents from "recma-mdx-escape-missing-components";

main();

async function main() {
const source = await read("example.mdx");

const compiledSource = await compile(source, {
recmaPlugins: [recmaEscapeMissingComponents],
recmaPlugins: [recmaMdxEscapeMissingComponents],
});

return String(compiledSource);
Expand All @@ -72,7 +72,7 @@ function _createMdxContent(props) {
}
```

Without the `recma-escape-missing-components`, you’d not get any Empty Component definition and default value for the components:
Without the `recma-mdx-escape-missing-components`, you’d not get any Empty Component definition and default value for the components:

```js
function _createMdxContent(props) {
Expand All @@ -82,7 +82,7 @@ function _createMdxContent(props) {
}
```

Basically, the `recma-escape-missing-components`;
Basically, the `recma-mdx-escape-missing-components`;

**inserts the Empty Component definition into the code above the function `_createMdxContent(props){}`**

Expand All @@ -101,7 +101,7 @@ Basically, the `recma-escape-missing-components`;
```typescript
type TestFunction = (componentName: string) => boolean | undefined | null;

function RecmaEscapeMissingComponents(test?: string | string[] | TestFunction)
function recmaMdxEscapeMissingComponents(test?: string | string[] | TestFunction)
```

#### `test`
Expand All @@ -126,7 +126,7 @@ Wellcome
#### Without the `test` option

```javascript
use(RecmaEscapeMissingComponents);
use(recmaMdxEscapeMissingComponents);
```

is going to produce the compiled source has the statement for all components have the default value:
Expand All @@ -136,7 +136,7 @@ is going to produce the compiled source has the statement for all components hav
#### With the `test` option (string)

```javascript
use(RecmaEscapeMissingComponents, "Component1");
use(recmaMdxEscapeMissingComponents, "Component1");
```

is going to produce the compiled source has the statement for only the `Component1` has the default value:
Expand All @@ -146,7 +146,7 @@ is going to produce the compiled source has the statement for only the `Componen
#### With the `test` option (string array)

```javascript
use(RecmaEscapeMissingComponents, ["Component1"]);
use(recmaMdxEscapeMissingComponents, ["Component1"]);
```
is going to produce the compiled source has the statement for only the `Component1` has the default value:

Expand All @@ -155,7 +155,7 @@ is going to produce the compiled source has the statement for only the `Componen
#### With the `test` option (function)

```javascript
use(RecmaEscapeMissingComponents, ((name) => name.endsWith("2")) as TestFunction);
use(recmaMdxEscapeMissingComponents, ((name) => name.endsWith("2")) as TestFunction);
```
is going to produce the compiled source has the statement for only the `Component2` has the default value:

Expand All @@ -175,7 +175,7 @@ This plugin works with unified version 6+ and estree version 2+. **It is compati

## Security

Use of `recma-escape-missing-components` does not involve user content so there are no openings for cross-site scripting (XSS) attacks.
Use of `recma-mdx-escape-missing-components` does not involve user content so there are no openings for cross-site scripting (XSS) attacks.

## License

Expand All @@ -195,13 +195,13 @@ Use of `recma-escape-missing-components` does not involve user content so there
[MDX]: https://mdxjs.com/
[MDXnpm]: https://www.npmjs.com/search?q=keywords:mdx
[typescript]: https://www.typescriptlang.org/
[license]: https://github.com/ipikuka/recma-escape-missing-components/blob/main/LICENSE
[license]: https://github.com/ipikuka/recma-mdx-escape-missing-components/blob/main/LICENSE
[markdownnpm]: https://www.npmjs.com/search?q=keywords:markdown
[recmaEMCnpm]: https://www.npmjs.com/search?q=keywords:recma%20custom%20escape%20missing%20components
[npm-url]: https://www.npmjs.com/package/recma-escape-missing-components
[npm-image]: https://img.shields.io/npm/v/recma-escape-missing-components
[github-license]: https://img.shields.io/github/license/ipikuka/recma-escape-missing-components
[github-license-url]: https://github.com/ipikuka/recma-escape-missing-components/blob/master/LICENSE
[github-build]: https://github.com/ipikuka/recma-escape-missing-components/actions/workflows/publish.yml/badge.svg
[github-build-url]: https://github.com/ipikuka/recma-escape-missing-components/actions/workflows/publish.yml
[npm-typescript]: https://img.shields.io/npm/types/recma-escape-missing-components
[npm-url]: https://www.npmjs.com/package/recma-mdx-escape-missing-components
[npm-image]: https://img.shields.io/npm/v/recma-mdx-escape-missing-components
[github-license]: https://img.shields.io/github/license/ipikuka/recma-mdx-escape-missing-components
[github-license-url]: https://github.com/ipikuka/recma-mdx-escape-missing-components/blob/master/LICENSE
[github-build]: https://github.com/ipikuka/recma-mdx-escape-missing-components/actions/workflows/publish.yml/badge.svg
[github-build-url]: https://github.com/ipikuka/recma-mdx-escape-missing-components/actions/workflows/publish.yml
[npm-typescript]: https://img.shields.io/npm/types/recma-mdx-escape-missing-components
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "recma-escape-missing-components",
"name": "recma-mdx-escape-missing-components",
"version": "1.0.2",
"description": "Recma plugin to set the default value `() => null` for the Components in MDX in case of missing or not provided.",
"type": "module",
Expand All @@ -24,7 +24,7 @@
],
"repository": {
"type": "git",
"url": "git+https://github.com/ipikuka/recma-escape-missing-components.git"
"url": "git+https://github.com/ipikuka/recma-mdx-escape-missing-components.git"
},
"keywords": [
"unified",
Expand All @@ -34,15 +34,15 @@
"mdxjs",
"recma",
"recma-plugin",
"recma-escape",
"recma-escape-components",
"recma-escape-missing-components"
"recma-mdx",
"escape missing components",
"recma-mdx-escape-missing-components"
],
"author": "ipikuka <talatkuyuk@gmail.com>",
"license": "MIT",
"homepage": "https://github.com/ipikuka/recma-escape-missing-components#readme",
"homepage": "https://github.com/ipikuka/recma-mdx-escape-missing-components#readme",
"bugs": {
"url": "https://github.com/ipikuka/recma-escape-missing-components/issues"
"url": "https://github.com/ipikuka/recma-mdx-escape-missing-components/issues"
},
"devDependencies": {
"@mdx-js/mdx": "^3.0.0",
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function statementOfEmptyComponent(): VariableDeclaration {
* This recma plugin sets the default value `() => null` for the Components in case them missing or not provided.
* in order "eval of the MDX compiled source" NOT to throw an error.
*
* The "recma-escape-missing-components" basically:
* The "recma-mdx-escape-missing-components" basically:
*
* inserts the Empty Component definition into code
*
Expand All @@ -75,7 +75,9 @@ function statementOfEmptyComponent(): VariableDeclaration {
* if "TestFunction", check the test function returns true.
* if check is true/pass, set the default value `() => null` for that component
*/
export default function RecmaEscapeMissingComponents(test?: string | string[] | TestFunction) {
export default function recmaMdxEscapeMissingComponents(
test?: string | string[] | TestFunction,
) {
return (tree: Node) => {
// inserts the Empty Component definition statement above the function _createMdxContent(props){}
visit(tree, (node, key, index, ancestors) => {
Expand Down
10 changes: 5 additions & 5 deletions tests/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { compile } from "@mdx-js/mdx";
import dedent from "dedent";

import recmaEscapeMissingComponents, { type TestFunction } from "../src";
import recmaMdxEscapeMissingComponents, { type TestFunction } from "../src";

describe("without the plugin", () => {
// ******************************************
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("with the plugin (no option)", () => {
`;

const compiledSource = await compile(source, {
recmaPlugins: [recmaEscapeMissingComponents],
recmaPlugins: [recmaMdxEscapeMissingComponents],
});

expect(String(compiledSource)).toContain("const _EmptyComponent = () => null;");
Expand All @@ -61,7 +61,7 @@ describe("with the plugin (has `test` option)", () => {
`;

const compiledSource = await compile(source, {
recmaPlugins: [[recmaEscapeMissingComponents, "Component1"]],
recmaPlugins: [[recmaMdxEscapeMissingComponents, "Component1"]],
});

expect(String(compiledSource)).toContain("const _EmptyComponent = () => null;");
Expand All @@ -84,7 +84,7 @@ describe("with the plugin (has `test` option)", () => {
`;

const compiledSource = await compile(source, {
recmaPlugins: [[recmaEscapeMissingComponents, ["Component1"]]],
recmaPlugins: [[recmaMdxEscapeMissingComponents, ["Component1"]]],
});

expect(String(compiledSource)).toContain("const _EmptyComponent = () => null;");
Expand All @@ -108,7 +108,7 @@ describe("with the plugin (has `test` option)", () => {

const compiledSource = await compile(source, {
recmaPlugins: [
[recmaEscapeMissingComponents, ((name) => name.endsWith("2")) as TestFunction],
[recmaMdxEscapeMissingComponents, ((name) => name.endsWith("2")) as TestFunction],
],
});

Expand Down

0 comments on commit 55925ac

Please sign in to comment.