Files
docuseal/lib/text_utils.rb
T
Pete Matsyburka 23dcd62672 add field mask
2025-03-03 00:18:56 +02:00

32 lines
630 B
Ruby

# frozen_string_literal: true
module TextUtils
RTL_REGEXP = /[\p{Hebrew}\p{Arabic}]/
MASK_REGEXP = /[^\s\-_\[\]\(\)\+\?\.\,]/
MASK_SYMBOL = 'X'
module_function
def rtl?(text)
return false if text.blank?
text.match?(TextUtils::RTL_REGEXP)
rescue Encoding::CompatibilityError
false
end
def mask_value(text)
text.to_s.gsub(MASK_REGEXP, MASK_SYMBOL)
end
def maybe_rtl_reverse(text)
if text.match?(RTL_REGEXP)
TwitterCldr::Shared::Bidi
.from_string(ArabicLetterConnector.transform(text), direction: :RTL)
.reorder_visually!.to_s
else
text
end
end
end