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

als-replace-between

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

als-replace-between - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

6

lib/base-node.js

@@ -13,4 +13,4 @@ const TextNode = require('./text-node')

if(child instanceof BaseNode === false) return
this.walkNodes(modifiers,child)
this.runModifiers(modifiers,child,true)
this.walkNodes(modifiers,child)
});

@@ -29,4 +29,4 @@ }

const isNode = child instanceof BaseNode
const result = this.runModifiers(modifiers,child,isNode)
if(isNode && result !== false) this.walk(modifiers,child)
if(isNode) this.walk(modifiers,child)
this.runModifiers(modifiers,child,isNode)
});

@@ -33,0 +33,0 @@ }

{
"name": "als-replace-between",
"version": "3.2.0",
"version": "3.3.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -346,15 +346,1 @@ # als-replace-between

This method is useful when you need consistent modifications across all elements of the structure, or when the modifications depend on the type of the element. It ensures that every element is processed, making it ideal for global updates.
#### Filtering
If some of modifiers returns false, the execution for this branch terminated, includes the next modifiers.
```js
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.walk([
(node,isNode) => {if(isNode && node.open === '<div>' && node.index === 0) return false},
(node,isNode) => {if(!isNode) node.outer = node.outer.toUpperCase()}
])
assert(result.outer === '<body><div><span>span 1</span></div><div><span>SPAN 2</span></div></body>')
```

@@ -95,2 +95,25 @@ const { describe, it, beforeEach } = require('node:test')

describe('inner and outer setters', () => {
it('root inner', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.inner = 'test'
assert(result.outer === 'test')
});
it('node inner', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.children[0].inner = 'test'
assert(result.outer === '<body>test</body>')
});
it('node outer', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.children[0].outer = 'test'
assert(result.outer === 'test')
});
})
describe('Method walk tests', () => {

@@ -145,39 +168,1 @@ it('should apply a single modifier to all nodes', () => {

});
describe('walk with false', () => {
it('should handle multiple levels of nested tags correctly', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.walk([
(node,isNode) => {if(isNode && node.open === '<div>' && node.index === 0) return false},
(node,isNode) => {if(!isNode) node.outer = node.outer.toUpperCase()}
])
assert(result.outer === '<body><div><span>span 1</span></div><div><span>SPAN 2</span></div></body>')
});
})
describe('inner and outer setters', () => {
it('root inner', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.inner = 'test'
assert(result.outer === 'test')
});
it('node inner', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.children[0].inner = 'test'
assert(result.outer === '<body>test</body>')
});
it('node outer', () => {
const content = "<body><div><span>span 1</span></div><div><span>span 2</span></div></body>";
const result = new ReplaceBetween(content, /<\w*>/, /<\/\w*>/);
result.children[0].outer = 'test'
assert(result.outer === 'test')
});
})
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