Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOW_TO for Dummies #98

Open
LostOverflow opened this issue Dec 16, 2021 · 0 comments
Open

HOW_TO for Dummies #98

LostOverflow opened this issue Dec 16, 2021 · 0 comments

Comments

@LostOverflow
Copy link

LostOverflow commented Dec 16, 2021

I'm newbie at JS
I tried to write very simple JS just to load response body from REST service and parse ANSI text into HTML and got stuck at the Usage example:

Usage
var Convert = require('ansi-to-html');
var convert = new Convert();

console.log(convert.toHtml('\x1b[30mblack\x1b[37mwhite'));

/*
prints: ...
*/

Got an exception:
Uncaught ReferenceError: require is not defined

Googling tries at stackoverflow also made me hurt:

https://stackoverflow.com/questions/19059580/client-on-node-js-uncaught-referenceerror-require-is-not-defined

`10 Answers

This is because require() does not exist in the browser/client-side JavaScript.

Now you're going to have to make some choices about your client-side JavaScript script management.

You have three options:

Use the <script> tag.
Use a CommonJS implementation. It has synchronous dependencies like Node.js
Use an asynchronous module definition (AMD) implementation.
CommonJS client side-implementations include (most of them require a build step before you deploy):

Browserify - You can use most Node.js modules in the browser. This is my personal favorite.
Webpack - Does everything (bundles JavaScript code, CSS, etc.). It was made popular by the surge of React, but it is notorious for its difficult learning curve.
Rollup - a new contender. It leverages ES6 modules and includes tree-shaking abilities (removes unused code).
You can read more about my comparison of Browserify vs (deprecated) Component.

AMD implementations include:

RequireJS - Very popular amongst client-side JavaScript developers. It is not my taste because of its asynchronous nature.
Note, in your search for choosing which one to go with, you'll read about Bower. Bower is only for package dependencies and is unopinionated on module definitions like CommonJS and AMD.`

OMG...
Use the <script> tag - I'd happy to use it ... but how to use it?

Is it possible to create a README for Dummies ? Is it possible to create just single script for ansi-to-html coverting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant