如何在Node.js中检查字符串是纯文本还是base64格式 [英] How to check if a string is plaintext or base64 format in Node.js

查看:234
本文介绍了如何在Node.js中检查字符串是纯文本还是base64格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查函数的给定字符串是纯文本还是base64格式.我能够将纯文本编码为base64格式并反转它. 但是我无法找到任何方法来验证字符串是否已经是base64格式.任何人都可以在node js中提出正确的方法建议吗?节点js中是否已经有用于执行此操作的API.

I want to check if the given string to my function is plain text or base64 format. I am able to encode a plain text to base64 format and reverse it. But I could not figure out any way to validate if the string is already base64 format. Can anyone please suggest correct way of doing this in node js? Is there any API for doing this already available in node js.

推荐答案

编码为字节级. 如果您要处理字符串,那么您所能做的就是猜测或保留带有字符串的元数据信息以进行识别

Encoding is byte level. If you're dealing in strings then all you can do is to guess or keep meta data information with your string to identify

但是您可以检出这些库:

But you can check these libraries out:

  1. https://www.npmjs.com/package/detect-encoding
  2. https://github.com/mooz/node-icu-charset-detector
  1. https://www.npmjs.com/package/detect-encoding
  2. https://github.com/mooz/node-icu-charset-detector

这篇关于如何在Node.js中检查字符串是纯文本还是base64格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆