pax_global_header 0000666 0000000 0000000 00000000064 14044026776 0014524 g ustar 00root root 0000000 0000000 52 comment=da4cc055366ce31535e34ed8760b59f7636e2ea6
applause-2.0.4/ 0000775 0000000 0000000 00000000000 14044026776 0013341 5 ustar 00root root 0000000 0000000 applause-2.0.4/.editorconfig 0000664 0000000 0000000 00000000223 14044026776 0016013 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
applause-2.0.4/.gitattributes 0000664 0000000 0000000 00000000023 14044026776 0016227 0 ustar 00root root 0000000 0000000 * text=auto eol=lf
applause-2.0.4/.github/ 0000775 0000000 0000000 00000000000 14044026776 0014701 5 ustar 00root root 0000000 0000000 applause-2.0.4/.github/workflows/ 0000775 0000000 0000000 00000000000 14044026776 0016736 5 ustar 00root root 0000000 0000000 applause-2.0.4/.github/workflows/main.yml 0000664 0000000 0000000 00000000664 14044026776 0020413 0 ustar 00root root 0000000 0000000 name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
applause-2.0.4/.gitignore 0000664 0000000 0000000 00000000027 14044026776 0015330 0 ustar 00root root 0000000 0000000 node_modules
yarn.lock
applause-2.0.4/.npmrc 0000664 0000000 0000000 00000000023 14044026776 0014454 0 ustar 00root root 0000000 0000000 package-lock=false
applause-2.0.4/CHANGELOG.md 0000664 0000000 0000000 00000001253 14044026776 0015153 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.0.3](https://github.com/outaTiME/applause/compare/v2.0.2...v2.0.3) (2021-05-03)
### Bug Fixes
* ignore non-string data types on replace ([bfbaa39](https://github.com/outaTiME/applause/commit/bfbaa39ba8123b9b8ab954b7964da0a831456ab8)), closes [#20](https://github.com/outaTiME/applause/issues/20)
### 2.0.2 (2021-05-03)
### Bug Fixes
* add type check before accesing String.replace ([93edf8e](https://github.com/outaTiME/applause/commit/93edf8ee3b0a36ab97797eb82061ecfd09ba97b3))
applause-2.0.4/README.md 0000664 0000000 0000000 00000024716 14044026776 0014632 0 ustar 00root root 0000000 0000000 # Applause 👏
[](https://travis-ci.org/outaTiME/applause)
[](https://www.npmjs.com/package/applause)

[](#)
[](https://twitter.com/outa7iME)
> Pattern replacer that helps to create human-friendly replacements.
**Try the [playground], where you can test every single option of applause.**
## Install
First make sure you have installed the latest version of [node.js](http://nodejs.org/)
(You may need to restart your computer after this step).
From NPM for programmatic use:
```shell
npm install applause
```
From Git:
```shell
git clone git://github.com/outaTiME/applause
cd applause
npm link .
```
## Usage
Assuming installation via NPM, you can use `applause` in your application like this:
```javascript
var fs = require('fs');
var Applause = require('applause');
var options = {
patterns: [
{
match: 'foo',
replacement: 'bar'
}
]
};
var applause = Applause.create(options);
var contents = '@@foo';
var result = applause.replace(contents);
console.log(result.content); // bar
```
## Options
### patterns
Type: `Array`
Defines the patterns that will be used to replace the content input.
### patterns.match
Type: `String|RegExp`
Indicates the matching expression.
If the match type is `String`, a simple variable search mechanism `@@string` is used (in any other case the default regexp replacement logic is used):
```javascript
{
patterns: [
{
match: 'foo',
replacement: 'bar' // Replaces "@@foo" with "bar"
}
]
}
```
### patterns.replacement or patterns.replace
Type: `String|Function|Object`
Indicates the replacement for match. For more information about replacement, see [String.replace].
You can specify a function as a replacement. In this case, the function will be invoked after the match has been made. The result of the function (return value) will be used as the replacement string.
```javascript
{
patterns: [
{
match: /foo/g,
replacement: function () {
return 'bar'; // Replaces "foo" with "bar"
}
}
]
}
```
Objects are also supported as replacement (a string representation of the object is created using [JSON.stringify]):
```javascript
{
patterns: [
{
match: /foo/g,
replacement: [1, 2, 3] // Replaces "foo" with string representation of the array
}
]
}
```
> The replacement only resolves the [special replacement patterns] when using regexp to match.
### patterns.json
Type: `Object`
If a `json` attribute is found in the pattern definition, the object is flattened using the [delimiter](#delimiter) concatenation and each key-value pair will be used for replacement (simple variable lookup mechanism and no regexp support).
```javascript
{
patterns: [
{
json: {
key: 'value' // Replaces "@@key" with "value"
}
}
]
}
```
Nested objects are also supported:
```javascript
{
patterns: [
{
json: {
key: 'value', // Replaces "@@key" with "value"
inner: { // Replaces "@@inner" with string representation of the "inner" object
key: 'value' // Replaces "@@inner.key" with "value"
}
}
}
]
}
```
You can define functions for deferred invocations:
```javascript
{
patterns: [
{
json: function (done) {
done({
key: 'value'
});
}
}
]
}
```
### patterns.yaml
Type: `String`
If a `yaml` attribute is found in the pattern definition, it will be converted and then processed as [json](#patternsjson) attribute.
```javascript
{
patterns: [
{
yaml: 'key: "value"' // Replaces "@@key" with "value"
}
]
}
```
You can define functions for deferred invocations:
```javascript
{
patterns: [
{
yaml: function (done) {
done('key: "value"');
}
}
]
}
```
### patterns.cson
Type: `String`
If a `cson` attribute is found in the pattern definition, it will be converted and then processed as [json](#patternsjson) attribute.
```javascript
{
patterns: [
{
cson: 'key: "value"'
}
]
}
```
You can define functions for deferred invocations:
```javascript
{
patterns: [
{
cson: function (done) {
done('key: "value"');
}
}
]
}
```
### variables
Type: `Object`
This is the old way of defining patterns using a simple plain object (simple variable lookup mechanism and no regexp support). You can still use this, but for more control you should use the new way of `patterns`.
```javascript
{
variables: {
'key': 'value' // Replaces "@@key" with "value"
}
}
```
### prefix
Type: `String`
Default: `@@`
The prefix used for matching (avoid wrong replacements / easy way).
> This only applies for simple variable lookup mechanism.
### usePrefix
Type: `Boolean`
Default: `true`
If set to "false", the pattern is matched without the "prefix" concatenation (this is useful when you want to lookup a simple string).
> This only applies for simple variable lookup mechanism.
### preservePrefix
Type: `Boolean`
Default: `false`
If set to "true", the "prefix" is preserved in the target.
> This only applies for simple variable lookup mechanism and when `patterns.replacement` is a string.
### delimiter
Type: `String`
Default: `.`
The delimiter used to flatten when using an object as a replacement.
### preserveOrder
Type: `Boolean`
Default: `false`
If set to "true", we preserve the order of definition of the patterns; otherwise the order will be ascending to avoid replacement problems such as "head" / "header" (regexp matches will be resolved at last).
[playground]: http://outatime.github.io/applause.io/
[String.replace]: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
[JSON.stringify]: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
[special replacement patterns]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
## Examples
### Basic
File `src/manifest.appcache`:
```
CACHE MANIFEST
# @@timestamp
CACHE:
favicon.ico
index.html
NETWORK:
*
```
Node:
```javascript
var fs = require('fs');
var Applause = require('applause');
var options = {
patterns: [
{
match: 'timestamp',
replacement: Date.now()
}
]
};
var applause = Applause.create(options);
var contents = fs.readFileSync('./src/manifest.appcache', 'utf8');
var result = applause.replace(contents);
console.log(result.content); // The replaced output
```
### Multiple matching
File `src/manifest.appcache`:
```
CACHE MANIFEST
# @@timestamp
CACHE:
favicon.ico
index.html
NETWORK:
*
```
File `src/humans.txt`:
```
__ _
_ _/__ /./|,//_`
/_//_// /_|/// //_, outaTiME v.@@version
/* TEAM */
Web Developer / Graphic Designer: Ariel Oscar Falduto
Site: https://www.outa.im
Twitter: @outa7iME
Contact: afalduto at gmail dot com
From: Buenos Aires, Argentina
/* SITE */
Last update: @@timestamp
Standards: HTML5, CSS3, robotstxt.org, humanstxt.org
Components: H5BP, Modernizr, jQuery, Bootstrap, LESS, Jade, Grunt
Software: Sublime Text, Photoshop, LiveReload
```
Node:
```javascript
var fs = require('fs');
var pkg = require('./package.json');
var Applause = require('applause');
var options = {
patterns: [
{
match: 'version',
replacement: pkg.version
},
{
match: 'timestamp',
replacement: Date.now()
}
]
};
var applause = Applause.create(options);
var contents = fs.readFileSync('./src/manifest.appcache', 'utf8');
var result = applause.replace(contents);
console.log(result.content); // The replaced output
contents = fs.readFileSync('./src/humans.txt', 'utf8');
result = applause.replace(contents);
console.log(result.content); // The replaced output
```
### Cache busting
File `src/index.html`:
```html