Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
apteryxxyz committed Sep 22, 2022
1 parent 2d5dd9a commit 80a998e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 42 deletions.
86 changes: 46 additions & 40 deletions examples/browser.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JSWhat Browser Example</title>

<script src="../dist/index.js"></script>
<script>
function whatIsThis() {
const results = document.getElementById('results');
const textbox = document.getElementById('textbox');

const text = textbox.value;
results.innerHTML = '';

const result = what.is(text);
const mapped = result.map((m) => {
return [
`Identified as: ${m.name}`,
`Matched at: ${m.matched}`,
`Description: ${m.description}`,
`Tags: ${m.tags.join(', ')}`,
].join('<br>');
});

results.innerHTML = 'Results: ' + result.length + '<br><br>' + mapped.join('<br><br>');
}
</script>
</head>
<body>
<p>Type something into the text input below and press 'WHAT?'</p>
<input id="textbox" type="text" style="width: 35%" />
<button onclick="whatIsThis()">WHAT?</button>
<br />
<br />
<span id="results"> </span>
</body>
</html>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JSWhat Browser Example</title>

<script src="../dist/index.js"></script>
<!-- <script src="https://unpkg.com/[email protected]/dist/index.js"></script> -->

<script>
function whatIsThis() {
const results = document.getElementById('results');
const input = document.getElementById('textbox');
results.innerHTML = '';

// The module will be defined as 'what'
const result = what.is(input.value);

const mapped = result.map((m) => {
return [
`Identified as: ${m.name}`,
`Matched at: ${m.matched}`,
`Description: ${m.description}`,
`Tags: ${m.tags.join(', ')}`,
].join('<br>');
});

results.innerHTML = 'Results: ' +
result.length + '\n\n' +
mapped.join('\n\n');
}
</script>
</head>

<body>
<p>Type something into the text input below and press 'WHAT?!'</p>
<input id="textbox" type="text" style="width:35%" />
<button onclick="whatIsThis()">WHAT?!</button>
<br/><br/>
<span id="results" style="white-space: pre-wrap;" />
</body>

</html>
23 changes: 23 additions & 0 deletions examples/node.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const what = require('..');
// const what = require('jswhat');

// General usage
const match = what.is('[email protected]')[0];
console.log('Simply match an email only\n', match.matched);

// Search with a string
var matches = what.is('[email protected] [email protected] [email protected]', { search: true });
const sMatched = matches.map((m) => m.matched);
console.log('\nFind every possible match within\n', sMatched.join(', '));

// Filter the output by a name, short name, category or tag
const fOptions = { search: true, filter: ['Email'] };
const filtered = what.is('[email protected] [email protected] [email protected]', fOptions);
const fMatched = filtered.map((m) => m.matched);
console.log('\nOnly match possible email addresses\n', fMatched.join(', '));

// Exclude a name, short name, category or tag
const eOptions = { search: true, exclude: ['URL', 'YouTube'] };
const excluded = what.is('[email protected] [email protected] https://youtube.com/pewdiepie', eOptions);
const eMatched = excluded.map((m) => m.matched);
console.log('\nExclude a property from the results, in this case URLs and YouTube related\n', eMatched.join(', '));
3 changes: 2 additions & 1 deletion examples/node.js → examples/node.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const what = require('../');
import what from '..';
// import what from 'jswhat';

// General usage
const match = what.is('[email protected]')[0];
Expand Down
3 changes: 2 additions & 1 deletion examples/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as what from '../';
import what from '..';
// import what from 'jswhat';

// General usage
const match = what.is('[email protected]')[0];
Expand Down

0 comments on commit 80a998e

Please sign in to comment.