1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(shortcodes): [strings] shortcode - add charsFrequency modifier

This commit is contained in:
Awilum
2022-05-05 07:12:41 +03:00
parent e3e077727b
commit f5c3f3867e
2 changed files with 7 additions and 0 deletions

View File

@@ -108,6 +108,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
if ($key == 'chars') {
$content = serializers()->json()->encode(strings($content)->{'chars'}());
}
if ($key == 'charsFrequency') {
$content = serializers()->json()->encode(strings($content)->{'charsFrequency'}());
}
}
return (string) $content;

View File

@@ -58,4 +58,7 @@ test('[strings] shortcode', function () {
// chars
$this->assertEquals('["c","a","r","_","f","ò","ô","_","b","à","ř","s","_","a","p","p","l","e"]', parsers()->shortcodes()->parse('[strings chars]car_fòô_bàřs_apple[/strings]'));
// charsFrequency
$this->assertEquals('{"_":"16.67","a":"11.11","p":"11.11","c":"5.56","r":"5.56","f":"5.56","ò":"5.56","ô":"5.56","b":"5.56","à":"5.56","ř":"5.56","s":"5.56","l":"5.56","e":"5.56"}', parsers()->shortcodes()->parse('[strings charsFrequency]car_fòô_bàřs_apple[/strings]'));
});