6.0.1 • Published 9 years ago

identify-resource v6.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

NPM Version Build Status

identify-resource

Resolve the file paths to js, css, and html dependencies.

Usage

resolve(sourcepath, id, options): resolve the path for id from sourcepath.

id can be an absolute filepath, relative filepath, "node_modules" reference, or "node_modules" file reference.

Available options include:

  • fileExtensions: hash of valid file extensions by type, used to resolve ids with missing file extension (default { js: 'js', 'json', css: 'css', html: 'html' })
  • sources: array of source directories (in addition to cwd and "node_modules") in which to search for files (default [])
$ npm install identify-resource

/projects/myproject/index.js

var bar = require('./bar')
  , boo = require('boo')
  , http = require('http');

/project/myproject/index.css

@import 'bar';

/projects/myproject/node_modules/boo/package.json

{
  "name": "boo",
  "version": "1.0.0",
  "main": "index.js"
}
var resolve = require('identify-resource').resolve;

// Resolve relative path
console.log(resolve('/projects/myproject/index.js', './bar')); 
//=> '/projects/myproject/bar.js'

// Resolve node_modules
console.log(resolve('/projects/myproject/index.js', 'boo')); 
//=> '/projects/myproject/node_modules/boo/index.js'

// Resolve native node modules
console.log(resolve('/projects/myproject/index.js', 'http')); 
//=> 'false'

// Resolve css
console.log(resolve('/projects/myproject/index.css', 'bar'));
//=> '/projects/myproject/bar.css'

Configuring the package.json browser field enables overriding default behaviour:

/projects/myproject/package.json

{
  "name": "myproject",
  "version": "1.0.0",
  "main": "index.js",
  "browser": {
    "http": "./lib/http.js"
  }
}
// Alias native module
console.log(resolve('/projects/myproject/index.js', 'http')); 
//=> '/projects/myproject/lib/http.js'

See here for more details on using the browser field.

identify(filepath, options): retrieve the id for filepath. Id's are resolved from the cwd or "node_modules", as appropriate.

var identify = require('identify-resouce').identify;

identify('/projects/myproject/bar.js'); //=> 'bar.js'
identify('/projects/myproject/boo/index.js'); //=> 'boo/index.js#1.0.0'
identify('/projects/myproject/bar.css'); //=> 'bar.css'

hasMultipleVersions(id): determine if more than one version of id exists in resolve cache

clearCache(): clear the resolve cache

6.0.1

9 years ago

5.1.2

9 years ago

5.1.1

9 years ago

5.1.0

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.1.1

9 years ago

4.1.0

10 years ago

4.0.0

10 years ago

3.0.0

10 years ago

2.2.0

10 years ago

2.0.1

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.0.0

10 years ago

0.13.4

10 years ago

0.13.3

10 years ago

0.13.2

10 years ago

0.13.1

10 years ago

0.13.0

10 years ago

0.12.0

10 years ago

0.11.0

10 years ago

0.10.0

11 years ago

0.9.1

11 years ago

0.9.0

11 years ago

0.8.1

11 years ago

0.8.0

11 years ago

0.7.5

11 years ago

0.7.4

11 years ago

0.7.3

11 years ago

0.7.2

11 years ago

0.7.1

12 years ago

0.7.0

12 years ago

0.6.2

12 years ago

0.6.1

12 years ago

0.5.0

12 years ago

0.4.3

12 years ago

0.4.2

12 years ago

0.4.1

12 years ago

0.4.0

12 years ago

0.3.0

12 years ago