# @austinjherman/ah-shortcodes

> An unopinionated and extensible shortcode parser that can process shortcodes anywhere in your content, from any CMS.

Latest version **1.0.1** (published 2021-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @austinjherman/ah-shortcodes
pnpm add @austinjherman/ah-shortcodes
yarn add @austinjherman/ah-shortcodes
bun add @austinjherman/ah-shortcodes
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-04-30 |
| First published | 2021-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Austin Herman |
| Maintainers | austinjherman |
| Keywords | shortcodes |

## Links

- npm: https://www.npmjs.com/package/@austinjherman/ah-shortcodes
- Repository: https://github.com/austinjherman/ah-shortcodes
- Homepage: https://github.com/austinjherman/ah-shortcodes#readme
- Issues: https://github.com/austinjherman/ah-shortcodes/issues
- npm.io page: https://npm.io/package/@austinjherman/ah-shortcodes

## Dependencies (1)

- [json5](https://npm.io/package/json5.md) ^2.1.3

## Recent versions

- 1.0.1 (latest) — 2021-04-30
- 1.0.0 — 2021-04-20

## README

# Shortcode Parser
Need shortcodes? This unopinionated and extensible shortcode parser can process shortcodes anywhere in your content, from any CMS. 

## Usage

### In Your Content

This is an example of using the shortcode parser in content. {{ type: "replace", content: "Hello, world!" }}<br/>
  
-> This is an example of using the shortcode parser in content. Hello, world!

This is another example using variables. {{ type: "replace", content: "Hello, \\${b.nested.value}!" }}<br/>

-> This is another example uusing variables. Hello, variables!


### In Code
```javascript

import ShortcodeParser from '@austinjherman/ah-shortcodes';

// We can feed the parser an object of variables to 
// use in our shortcodes.
const variables = {
  a: "ice cream",
  b: {
    nested: {
      value: "variables"
    }
  },
  c: "wine"
};

// We can write a simple function to run over our content.
// This function will simply replace the shortcode with the 
// content inside of it.
const replaceParser = (content, obj, originalMatch) => {
  const objType = obj.type;
  if(objType === 'replace') {
    const updatedContent = obj.content;
    content = content.replace(originalMatch, updatedContent);
  }
  return content;
};
      
// Write as many filter functions as you want.
const filterFunctions = [replaceParser];

// Instantiate the parser.
sp = new ShortcodeParser(variables, filterFunctions);

// Resolve your shortcodes.
sp.parse("Your content here!! {{ type: 'replace', content: 'example' }}");
```

## Development

### Installation
- clone this repo
- `npm i`

### Run Tests
- `node ./test/shortcodeParser.test.js`

---
_Source: https://npm.io/package/@austinjherman/ah-shortcodes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
