# tm_require

> A library for asynchronous reference to Javascript, html, css.

Latest version **1.0.13** (published 2019-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install tm_require
pnpm add tm_require
yarn add tm_require
bun add tm_require
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.13 |
| Published | 2019-07-06 |
| First published | 2018-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 68.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Tommy Hu, huqi1980 |
| Maintainers | huqi1980 |
| Keywords | javascript, js, html, css, load, load, web, restful, require, require_js, require_css, require_html |

## Links

- npm: https://www.npmjs.com/package/tm_require
- Repository: https://github.com/huqi1980/require
- Homepage: https://github.com/huqi1980/require#readme
- Issues: https://github.com/huqi1980/require/issues
- npm.io page: https://npm.io/package/tm_require

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.13 (latest) — 2019-07-06
- 1.0.12 — 2019-01-12
- 1.0.11 — 2019-01-10
- 1.0.10 — 2019-01-10
- 1.0.9 — 2019-01-04
- 1.0.8 — 2019-01-04
- 1.0.7 — 2019-01-04
- 1.0.6 — 2018-12-28
- 1.0.5 — 2018-12-27
- 1.0.4 — 2018-12-27
- 1.0.3 — 2018-12-27

## README

# require

require is a library for asynchronous reference to Javascript, html, css.

[![Build Status](https://travis-ci.com/huqi1980/require.svg?branch=master)](https://travis-ci.org/huqi1980/require)
[![codecov](https://codecov.io/gh/huqi1980/require/branch/master/graph/badge.svg)](https://codecov.io/gh/huqi1980/require)
[![MIT](https://img.shields.io/npm/l/tm_require.svg)](https://github.com/huqi1980/require/blob/master/LICENSE)
[![size](https://img.shields.io/github/languages/code-size/huqi1980/require.svg)](https://github.com/huqi1980/require)
[![V](https://img.shields.io/npm/v/tm_require.svg)](https://www.npmjs.com/package/tm_require)
[![commit](https://img.shields.io/github/last-commit/huqi1980/require.svg)](https://github.com/huqi1980/require)


---

# Building & Testing

Current build process uses Gulp, and Karma related repos.

**build**

	$ npm i -g gulp-cli karma-cli
	$ npm install
	$ gulp                # or
	$ gulp build          # to only build the source, or
	$ gulp demo           # to only build the demo

**test**

	$ npm run test

# Sample

add "script" tag in your html file:

```html
<script src="require.js"></script>
```

require a javascript modue:

```js
require.js("jquery.js", function(modules){
    //your code
});
```

require a css modue:

```js
//load css for document
require.css("style.css", function(styles){
    //your code
});

//load css for dom
require.css("style.css", {dom, $("content")}, function(styles){
    //your code
});

//load css with dom
node.loadCss("style.css", function(styles){
    //your code
});
```

remove a css modue:

```js
require.css.remove("style.css");
```

require a html modue:

```js
//load html for dom
require.css("list.html", {dom, $("content")}, function(htmls){
    //your code
});

//load html with dom
node.loadHtml("list.html", function(htmls){
    //your code
});
```

require js,html,css modue:

```js
require({
    "html": "test.html",
    "css": "test.css",
    "js": "test.js"
}, function(htmls, styles, modules){
    //your code
});
```
# API #


**◆ require.js(modules, [options, callback])**

require one or more javascript files.

**parameters**

***modules***：`string` or `array` the javascript path

***options***: `object`

> *-noCache*: `boolean` default is `false`

> *-reload*: `boolean` default is `false`

> *-sequence*: `boolean` default is `false`. if this value is `true` and modules is `array`,  they will load in order, otherwise the load order is not guaranteed.

> *-doc*: `HTMLDocument` default is `document`


***callback***: `function` this Callback function, Receives the modules array as arguments.

> *-modules[i].module*: this javascript path

> *-modules[i].id*: a uuid for this module

**example**

```js
require.js("jquery.js", function(modules){
    //your code
});

require.js(["code1.js", "code2.js"], {"noCache": true}, function(modules){
    //your code
});
```

----------


**◆ require.css(modules, [options, callback])**

require one or more css files.

**parameters**

***modules***：`string` or `array` the css path

***options***: `object`

> *-noCache*: `boolean` default is `false`

> *-reload*: `boolean` default is `false`

> *-sequence*: `boolean` default is `false`. if this value is `true` and modules is `array`,  they will load in order, otherwise the load order is not guaranteed.

> *-dom*: `HTMLElement`or `string` or `array` default is `null`, this value can be HTMLElement or css selector. If this value is supplied, css will take effect on this dom object.

> *-doc*: `HTMLDocument` default is `document`


***callback***: `function` this Callback function, Receives the modules array as arguments.

> *-modules[i].module*: this css path

> *-modules[i].id*: a uuid for this css module

> *-modules[i].style*: a HTMLStyleElement

**example**

```js
require.css("style.css", function(modules){
    //your code
});

require.css(["style1.css", "style2.css"], {"dom": [".content", ".list", document.getElementById("id")]}, function(modules){
    //your code
});


document.getElementById("id").loadCss(["style1.css", "style2.css"], function(){
	//your code
});
```

----------

**◆ require.css.remove(modules, [doc])**

remove a css (required by "require.css") from document

**parameters**

***module***：`string` the css path, same as require.css; or thie css module uuid (received in the callback function when require.css).

***doc***：`HTMLDocument` default is `document`.

----------

**◆ require.html(modules, [options, callback])**

require one or more html files.

**parameters**

***modules***：`string` or `array` the html path

***options***: `object`

> *-noCache*: `boolean` default is `false`

> *-reload*: `boolean` default is `false`

> *-sequence*: `boolean` default is `false`. if this value is `true` and modules is `array`,  they will load in order, otherwise the load order is not guaranteed.

> *-dom*: `HTMLElement`or `string` or `array` default is `null`, this value can be HTMLElement or css selector. If this value is supplied, Html content will be append to these doms

> *-doc*: `HTMLDocument` default is `document`

> *-position*: `string` default is `beforeend`. where this html appended. this value can be `beforebegin` `afterbegin` `beforeend` `afterend`


***callback***: `function` this Callback function, Receives the modules array as arguments.

> *-modules[i].module*: this html path

> *-modules[i].id*: a uuid for this html module

> *-modules[i].data*: thie html text

**example**

```js
require.html("tp.html", function(modules){
    //your code
});

require.html(["tp1.html", "tp1.html"], {"dom": [".content", ".list", document.getElementById("id")]}, function(modules){
    //your code
});

document.getElementById("id").loadHtml(["tp1.html", "tp2.html"], function(){
	//your code
});
```

----------

**◆ require(modules, [options, callback])**

require one or more html, css, javascript files.

**parameters**

***modules***：`object` the html, css, javascript path.

> *-html*: `string` or `array` the html path, like require.html modules

> *-css*: `string` or `array` the css path, like require.css modules

> *-js*: `string` or `array` the javascript path, like require.js modules


***options***: `object` see require.html options

***callback***: `function` this Callback function, Receives the htmls array, styles array and modules array as arguments.

> *-htmls*: see require.html callback

> *-styles*: see require.css callback

> *-modules*: see require.js callback

# License

[MIT License](https://en.wikipedia.org/wiki/MIT_License)

---
_Source: https://npm.io/package/tm_require · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
