-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.example.js
34 lines (30 loc) · 1.06 KB
/
report.example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Use import from "hsa-js"
// import HtmlStringsAffixer from "hsa-js";
import HtmlStringsAffixer from "./../src/htmlStringsAffixer.js";
// Example of using HtmlStringsAffixer in a Laravel Blade template
const bladeTemplateContent = `
<div>
<h1>Welcome to our website</h1>
<p>{{stayEnjoyment}}</p>
<a href="/contact">Contact us</a>
<h2>Welcome to our website</h2>
</div>
`;
const affixer = new HtmlStringsAffixer({
prefix: "{{ __('", // Prefix to add before string
suffix: "') }}", // Suffix to add after string
extractions: [
"text", // Since we have only texts
],
});
/*
If you pass the second arguments of affixIt method as "true", it will report info in console
Also, it will return 2 values:
content - Localized (Affixed) content
report - detailed info about replacement and all warnings
*/
const { content, report } = affixer.affixIt(bladeTemplateContent, true);
console.log(content);
console.log(report);
// console.log(affixer.foundStrings.data);
// console.log(affixer.foundStrings.data[0]);