Giter Site home page Giter Site logo

d3-require's Introduction

d3-require

A minimal, promise-based implementation to require asynchronous module definitions (AMD). This implementation is about 50 lines of code and supports a strict subset of AMD. It is designed to work with browser-targeting libraries that implement one of the recommended UMD patterns. The constraints of this implementation are:

  • The define method must be called synchronously by the library on load.

  • Only anonymous module definitions are allowed; no named modules.

  • Only the built-in exports dependency is allowed; no require or module as in CommonJS.

By default, d3.require loads modules from unpkg; the module name can be any package (or scoped package) name optionally followed by the at sign (@) and a semver range. For example, d3.require("d3@4") loads the highest version of D3 4.x. You can change this behavior using d3.requireFrom.

Installing

If you use NPM, npm install d3-require. Otherwise, download the latest release. You can also load directly from unpkg.com. AMD, CommonJS, and vanilla environments are supported. In vanilla, d3 and define globals are exported:

<script src="https://unpkg.com/d3-require@0"></script>
<script>

d3.require("d3-array").then(d3 => {
  console.log(d3.range(100));
});

</script>

API Reference

# d3.require(names…) <>

To load a module:

d3.require("d3-array").then(d3 => {
  console.log(d3.range(100));
});

To load two modules and merge them into a single object:

d3.require("d3-array", "d3-color").then(d3 => {
  console.log(d3.range(360).map(h => d3.hsl(h, 1, 0.5)));
});

To load a module within a version range:

d3.require("d3-array@1").then(d3 => {
  console.log(d3.range(100));
});

# d3.requireFrom(source) <>

Returns a new require function which loads modules from the specified source, which is a function that takes a module name and returns the corresponding URL. For example, the default implementation works something like this:

var requireUnpkg = d3.requireFrom(name => `https://unpkg.com/${name}`);

requireUnpkg("d3-array").then(d3 => {
  console.log(d3.range(100));
});

d3-require's People

Contributors

mbostock avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.