jswhat

Identify anything. jsWhat lets you easily identify emails, IP addresses, and more. Works in Node, Deno, the browser and the command line.

Usage no npm install needed!

<script type="module">
  import jswhat from 'https://cdn.skypack.dev/jswhat';
</script>

README

jsWhat
The easiest way to identify anything
npm install jswhat

jswhat version total downloads
node version deno version
chrome version IE version edge version firefox version safari version opera version
javascript percentage jswhat code size license
github commit activity code style prettier
apteryxxyz followers jswhat repo stars

🤔 What is what?

jsWhat is a JavaScript version of the existing pyWhat. Works in Node, Deno, the browser and the command line.

Have you ever come across a mysterious 🧙‍♂️ piece of text and wondered what it might be? Perhaps something like rBxwE6ivExFJjRPh5cZtpq1ghTDm6cV5YP or 2001:0db8:85a3:0000:0000:8a2e:0370:7334? Well with what all you have to do is ask via one of the four available methods and it will tell you! Simply feed what one or more pieces of text and it will try to identify them.

whats' job is to help you by identifing what something is. Not only does it have ability to identify single pieces of inputted text, but it can also read and identify the contents of a file, as well as being able to fetch data from a URL and identify the text within it.

Check out a live example at JSFiddle.

🏓 Table Of Contents

📩 Installation

Command Line using NPM:

npm install jswhat --global

Node using NPM:

npm install jswhat

Browser using unpkg CDN:

<script src="https://unpkg.com/jswhat@1.0.1/dist/what.min.js"></script>

Deno using NPM:

View usage here.

🍕 Documentation

💻 Command Line

node support versions

Once installed globally, you will gain access to the what command. You can use what --help to see a basic help menu containing usage, option infromation and examples. You can also use the command jswhat, which is just an alias for what.

Usage

what <text> [options]

Options

 -h, --help                Show help message.
 -v, --version             Show the installed version of jsWhat.
 -s, --search              Search globally within a string.
 -n, --non-text            The text input is a file path or URL.
 -t, --tags                Show all the available tags.
 -f, --filter              Filter the results by names or tags, separate by commons.
 -e, --exclude             Exclude results based on names and tags, separate by commons.

Text

When wanting to identify some basic text, just type what <text> and what will try to identify what it is, simple right? You can identify more than one piece of text by simply feeding what more strings (with spaces in between), like what <text> <text> <text>. In fact, any argument that does not start with a dash (-) will be treated as a string to identify.

Non-Text

You also have the ability to use what to read a file and fetch data from a URL. All you need to do is pass a file path or URL as the text argument and enable the non-text option. Examples what ./src/data/regexes.json --non-text, what https://data.iana.org/TLD/tlds-alpha-by-domain.txt -n. The non-text is required to ensure you are meaning to read a file or fetch a URL, as you could be looking to identify the path to the file or URL itself instead.

🟢 Node

node version

Node Examples

The node module is very simply to use, containing only a single method.

<what>.is(<text>, [search], [options])

  • <text> {string} Text to be identified.
  • [search] {boolean} Search the text globally.
  • [options.nonText] {boolean} Wether or not the text should be treated as a file path or URL.
  • [options.filter] {string|string[]} Names or tags to filter results by.
  • [options.exclude] {string|string[]} Names or tags to exclude from the results.
  • [options.promise] {boolean} = Force the method to return a promise.
  • [options.throwError] {boolean} = In case of an error, throw it instead of saving it to the 'error' property.

The above method returns an array containing objects. Format is as follows:

[
  {
    "matched": String, // the content that was identified
    "name": String, // what it was identified as
    "description": String, // a description of what was identified
    "url": String, // a URL, sometimes linking to somewhere with more information
    "regex": RegExp, // the regex that was used to identify the text
    "tags": String[] // array of tags for the identified
  },
  ...
  text: String[], // the strings passed into the method
  error: Error, // if the method produces an error, it will appear in this property
  names: String[], // shortname for <matched>.map(m => m.name)
  matched: String[], // shortname for <matched>.map(m => m.matched)
  tags: String[] // shortname for <matched>.map(m => m.tags).flat().filter((m, i, s) => s.indexOf(m) === i)
]

📺 Browser

chrome version IE version edge version firefox version safari version opera version

Browser Examples

jsWhat works in almost the exact same way in the browser as in NodeJS, although without the ability to read a file.

<script src="https://unpkg.com/jswhat@1.0.1/dist/what.min.js"></script>

<what>.is(<text>, [search], [options])

  • <text> {string} = Content to be identified.
  • [search] {boolean} = Wether or not to search the content globally.
  • [options.nonText] {boolean} = Wether or not the text should be treated as a URL.
  • [options.filter] {string|string[]} = A string or array of names or tags to filter results by.
  • [options.exclude] {string|string[]} = A string or array of names or tags to exclude from the results.

The above method returns an array containing objects. Format is the same as in Node.

🐱‍🐉 Deno

deno version

Note: Not completely tested

Deno Examples

In order to use jsWhat in Deno you must use the 'Deno standard library' 'node/module.ts'. Other than that the use of jsWhat in Deno is almost exactly the same as in Node, so refer to that documentation in most cases.

npm install jswhat
// deno.js
import { createRequire } from 'https://deno.land/std/node/module.ts';
const require = createRequire(import.meta.url);
const what = require('jswhat');
deno run --unstable --allow-read deno.js