util.wxs 644 B

123456789101112131415161718192021222324
  1. function desensitization(string="", start, end) {
  2. var star = ''
  3. var length = string.length
  4. function makeStar(number) {
  5. if (number > 0) {
  6. star += '*';
  7. return makeStar(--number)
  8. } else {
  9. return star
  10. }
  11. };
  12. if(length < end) {
  13. return string.substring(0, 1) + makeStar(length-2>0?length-2:0) + (length>2?string.substring(length-1):"")
  14. }
  15. return string.substring(0, start) + makeStar(end - start) + string.substring(end)
  16. }
  17. function indexOf(array, value) {
  18. return array.indexOf(value)
  19. }
  20. module.exports = {
  21. desensitization: desensitization,
  22. indexOf:indexOf,
  23. }