https://github.com/hugoalh-studio/replaceholder-es
An ES (JavaScript & TypeScript) module for literal string template.
https://github.com/hugoalh-studio/replaceholder-es
es javascript js modulejs replaceholder ts typescript
Last synced: 7 months ago
JSON representation
An ES (JavaScript & TypeScript) module for literal string template.
- Host: GitHub
- URL: https://github.com/hugoalh-studio/replaceholder-es
- Owner: hugoalh-studio
- License: other
- Created: 2024-01-23T07:32:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-13T03:06:20.000Z (over 1 year ago)
- Last Synced: 2024-04-13T16:36:07.185Z (over 1 year ago)
- Topics: es, javascript, js, modulejs, replaceholder, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Replaceholder (ES)
[**âī¸** MIT](./LICENSE.md)
[](https://github.com/hugoalh-studio/replaceholder-es)
[](https://jsr.io/@hugoalh/replaceholder)
[](https://www.npmjs.com/package/@hugoalh/replaceholder)An ES (JavaScript & TypeScript) module for literal string template.
## đ° Begin
### đ¯ Targets
| | **Registry - JSR** | **Registry - NPM** | **Remote Import** |
|:--|:--|:--|:--|
| **[Bun](https://bun.sh/)** >= v1.1.0 | [âī¸ `node_modules`](https://jsr.io/docs/npm-compatibility) | [âī¸ Specifier `npm:`](https://bun.sh/docs/runtime/autoimport) | â |
| **[Cloudflare Workers](https://workers.cloudflare.com/)** | [âī¸ `node_modules`](https://jsr.io/docs/with/cloudflare-workers) | [âī¸ `node_modules`](https://docs.npmjs.com/using-npm-packages-in-your-projects) | â |
| **[Deno](https://deno.land/)** >= v1.42.0 | [âī¸ Specifier `jsr:`](https://jsr.io/docs/with/deno) | [âī¸ Specifier `npm:`](https://docs.deno.com/runtime/manual/node/npm_specifiers) | [âī¸](https://docs.deno.com/runtime/manual/basics/modules/#remote-import) |
| **[NodeJS](https://nodejs.org/)** >= v16.13.0 | [âī¸ `node_modules`](https://jsr.io/docs/with/node) | [âī¸ `node_modules`](https://docs.npmjs.com/using-npm-packages-in-your-projects) | â |> **âšī¸ Note**
>
> It is possible to use this module in other methods/ways which not listed in here, however it is not officially supported.### #ī¸âŖ Registries Identifier
- **JSR:**
```
@hugoalh/replaceholder
```
- **NPM:**
```
@hugoalh/replaceholder
```> **âšī¸ Note**
>
> - Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub paths.
> - It is recommended to use this module with tag for immutability.### #ī¸âŖ Remote Import Paths
- **GitHub Raw:** (Require Tag)
```
https://raw.githubusercontent.com/hugoalh-studio/replaceholder-es/${Tag}/mod.ts
```> **âšī¸ Note**
>
> - Although it is recommended to import the entire module with the main path `mod.ts`, it is also able to import part of the module with sub path if available, but do not import if:
>
> - it's file path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
> - it is a benchmark or test file (e.g.: `foo.bench.ts`, `foo.test.ts`), or
> - it's symbol has an underscore prefix (e.g.: `export function _baz() {}`).
>
> These elements are not considered part of the public API, thus no stability is guaranteed for them.
> - Although there have 3rd party services which provide enhanced, equal, or similar methods/ways to remote import the module, beware these services maybe inject unrelated elements and thus affect the security.### đĄī¸ Permissions
*This module does not require any permission.*
## đ§Š APIs
- ```ts
class Replaceholder {
constructor(options: ReplaceholderOptions = {}): Replaceholder;
handle(item: string, data: KeyValueLike): string;
static handle(item: string, data: KeyValueLike, options: ReplaceholderOptions = {}): string;
}
```
- ```ts
function replaceholder(item: string, data: KeyValueLike, options: ReplaceholderOptions = {}): string;
```
- ```ts
interface ReplaceholderOptions {
/**
* Pattern for the tag close.
* @default "}}"
*/
close?: string;
/**
* Pattern for the tag open.
* @default "{{"
*/
open?: string;
}
```
- ```ts
type KeyValueLike = { [key: string]: string; } | Map | Record;
```> **âšī¸ Note**
>
> For the prettier documentation, can visit via:
>
> - [Deno CLI `deno doc`](https://deno.land/manual/tools/documentation_generator)
> - [JSR](https://jsr.io/@hugoalh/replaceholder)## âī¸ Examples
- ```ts
new Replaceholder().handle("This is {{name}}, {{age}} years old, and likes to use \"\\{{replaceholder}}\"!", {
age: "18",
name: "Bob"
});
//=> "This is Bob, 18 years old, and likes to use \"{{replaceholder}}\"!"
```