Skip to content

Suggested fixes to npm install #19

@kristianmandrup

Description

@kristianmandrup

Change name entry in package.json file to a valid npm name

Try the tool validate-npm-package-name to validate it

"name": "@EastDesire/jscolor", -> change to "name": "@eastdesire/jscolor", - note: must be all lowercase

Add node module exports

Copy jscolor.js file to jscolor-node.js file and add module exports:

module.exports = window.jscolor // default export
exports.jscolor = window.jscolor // named export

Now point the main entry in package.json to jscolor-node.js

This will make it available for NodeJS projects in a compatible way (See https://stackoverflow.com/questions/30241729/how-do-i-perform-an-export-that-is-compatible-with-es5-and-es6). The compatibility is handled by a transpiler such as Babel for pure javascript or in TypeScript by the compiler itself.

ES6 module usage example (using import)

import * as JsColor from "@eastdesire/jscolor";
const element = document.createElement("x");
const picker = new JsColor(element);

Old style NodeJs usage example (using require)

const JsColor = require("@eastdesire/jscolor")
const element = document.createElement("x");
const picker = new JsColor(element);

Since jscolor is also exported as a name constant (via export.jscolor) you can also import as follows:

const { jscolor } = require("@eastdesire/jscolor")

Similarly for ES5 import

import { jscolor } from "@eastdesire/jscolor";

You can then export more named constants as needed to make it easier to use.

You might want to have a look at my TypeScript conversion for how to convert it to a proper Javascript class, if that is the direction you want to take it... Makes it much easier to extend and customise for the end user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions