summary refs log tree commit diff
path: root/ReferenceClientProxyImplementation/Patches/Implementations/JSPatches/BooleanPatch.cs
blob: 152a3f3f884c17b8f1354e1054b6971a94a3a12d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Text;

namespace ReferenceClientProxyImplementation.Patches.Implementations.JSPatches;

public class BooleanPatch : IPatch {
    public int GetOrder() => 0;

    public string GetName() => "Use real booleans in JS files";
    public bool Applies(string relativeName, byte[] content) => relativeName.EndsWith(".js");

    public async Task<byte[]> Execute(string _, byte[] content) {
        var stringContent = Encoding.UTF8.GetString(content);

        stringContent = stringContent
            .Replace("return!", "return !")
            .Replace("!0", "true")
            .Replace("!1", "false");

        return Encoding.UTF8.GetBytes(stringContent);
    }
}