Skip to content

Add example for replace with callback function in documentation #77

@blaues0cke

Description

@blaues0cke

Missed this and had to grab the code from some pull requests. Will do this maybe later by myself. I used this to replace a placeholder everytime it gets matched with another class name:

var wallpapers = [
    'form',
    'drops',
    'circles',
    'fire',
    'flowers'
];
var wallpaperKey = 0;

subStream = subStream.pipe(plugins.replace('NEXTWALLPAPERCLASS', function ()
{
    var currentWallpaper = wallpapers[wallpaperKey];

    ++wallpaperKey;

    if (wallpaperKey >= wallpapers.length)
    {
        wallpaperKey = 0;
    }

    return 'wallpaper-' + currentWallpaper;
}));

So this will make:

<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>

To:

<div class="form">Foo</div>
<div class="drops">Foo</div>
<div class="circles">Foo</div>
<div class="fire">Foo</div>
<div class="flowers">Foo</div>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions