New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

broccoli-replace

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-replace - npm Package Compare versions

Comparing version 0.3.1 to 0.3.3

6

package.json
{
"name": "broccoli-replace",
"description": "Replace text patterns with applause.",
"version": "0.3.1",
"version": "0.3.3",
"homepage": "http://github.com/outaTiME/broccoli-replace",

@@ -31,5 +31,5 @@ "author": {

"dependencies": {
"broccoli-filter": "^0.1.6",
"broccoli-filter": "^0.2.0",
"minimatch": "^2.0.0",
"applause": "0.4.1"
"applause": "0.4.3"
},

@@ -36,0 +36,0 @@ "devDependencies": {

@@ -44,227 +44,7 @@ # broccoli-replace [![Build Status](https://secure.travis-ci.org/outaTiME/broccoli-replace.png?branch=master)](http://travis-ci.org/outaTiME/broccoli-replace)

#### patterns
Type: `Array`
Define patterns that will be used to replace the contents of source files.
#### patterns.match
Type: `String|RegExp`
Indicates the matching expression.
If matching type is `String` we use a simple variable lookup mechanism `@@string` (in any other case we use the default regexp replace logic):
```javascript
{
patterns: [
{
match: 'foo',
replacement: 'bar' // replaces "@@foo" to "bar"
function () {
var name = 'Applause Options';
return sections[name] || '_(Coming soon)_'; // empty
}
]
}
```
#### patterns.replacement or patterns.replace
Type: `String|Function|Object`
Indicates the replacement for match, for more information about replacement check out the [String.replace].
You can specify a function as replacement. In this case, the function will be invoked after the match has been performed. The function's result (return value) will be used as the replacement string.
```javascript
{
patterns: [
{
match: /foo/g,
replacement: function () {
return 'bar'; // replaces "foo" to "bar"
}
}
]
}
```
Also supports object as replacement (we create string representation of object using [JSON.stringify]):
```javascript
{
patterns: [
{
match: /foo/g,
replacement: [1, 2, 3] // replaces "foo" with string representation of "array" object
}
]
}
```
[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
#### patterns.json
Type: `Object`
If an attribute `json` found in pattern definition we flatten the object using `delimiter` concatenation and each key–value pair will be used for the replacement (simple variable lookup mechanism and no regexp support).
```javascript
{
patterns: [
{
json: {
"key": "value" // replaces "@@key" to "value"
}
}
]
}
```
Also supports nested objects:
```javascript
{
patterns: [
{
json: {
"key": "value", // replaces "@@key" to "value"
"inner": { // replaces "@@inner" with string representation of "inner" object
"key": "value" // replaces "@@inner.key" to "value"
}
}
}
]
}
```
For deferred invocations is possible to define functions:
```javascript
{
patterns: [
{
json: function (done) {
done({
key: 'value'
});
}
}
]
}
```
#### patterns.yaml
Type: `String`
If an attribute `yaml` found in pattern definition will be converted and then processed like [json attribute](#patternsjson).
```javascript
{
patterns: [
{
yaml: 'key: value' // replaces "@@key" to "value"
}
]
}
```
For deferred invocations is possible to define functions:
```javascript
{
patterns: [
{
yaml: function (done) {
done('key: value');
}
}
]
}
```
#### patterns.cson
Type: `String`
If an attribute `cson` found in pattern definition will be converted and then processed like [json attribute](#patternsjson).
```javascript
{
patterns: [
{
cson: 'key: \'value\''
}
]
}
```
For deferred invocations is possible to define functions:
```javascript
{
patterns: [
{
cson: function (done) {
done('key: \'value\'');
}
}
]
}
```
#### variables
Type: `Object`
This is the old way to define patterns using plain object (simple variable lookup mechanism and no regexp support). You can still use this but for more control you should use the new `patterns` way.
```javascript
{
variables: {
'key': 'value' // replaces "@@key" to "value"
}
}
```
#### prefix
Type: `String`
Default: `@@`
The prefix added for matching (prevent bad replacements / easy way).
> This only applies for simple variable lookup mechanism.
#### usePrefix
Type: `Boolean`
Default: `true`
If set to `false`, we match the pattern without `prefix` concatenation (useful when you want to lookup an simple string).
> This only applies for simple variable lookup mechanism.
#### preservePrefix
Type: `Boolean`
Default: `false`
If set to `true`, we preserve the `prefix` in target.
> This only applies for simple variable lookup mechanism and `patterns.replacement` is an string.
#### delimiter
Type: `String`
Default: `.`
The delimiter used to flatten when using object as replacement.
#### preserveOrder
Type: `Boolean`
Default: `false`
If set to `true`, we preserve the patterns definition order, otherwise these will be sorted (in ascending order) to prevent replacement issues like `head` / `header` (typo regexps will be resolved at last).
#### detail
Type: `Boolean`
Default: `false`
If set to `true`, return a object response with the `content` and `detail` of replace operation.
### Usage Examples

@@ -503,2 +283,3 @@

* 2015-08-06   v0.3.3   Fix issue with special characters attributes ($$, $&, $`, $', $n or $nn) on JSON, YAML and CSON.
* 2015-05-07   v0.3.1   Fix regression issue with empty string in replacement.

@@ -505,0 +286,0 @@ * 2015-05-01   v0.3.0   Update to [applause](https://github.com/outaTiME/applause) v0.4.0.

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