npm

@bit/bundler-utils

5.1.3 • Public • Published

bit-bundler-utils

Greenkeeper badge

nodejs helpers for bit-bundler and bit-imports

uniqueId.getId

Method that generates numeric ids from module ids, which are the full path for the module on storage.

  • @param {string} moduleId - module id generated by bit-loader to convert to module id consumed by bit-bundler.

  • @returns {int} module id to be consumed by bit-bundler.

uniqueId.getId will cache the results it produces so that subsequent calls with the same input generates the exact same output.

uniqueId.setId

Method to set an id, that is treated as unique. It can only be set to one value... If an attempt to set it the id to a different value once it is set, an exception is raised.

  • @param {string} moduleId - module id generated by bit-loader.
  • @param {string} value - unique value to be mapped to the module id.

uniqueId.setId can be called multiple times with the same value successfully.

resolvePath

Helper method for resolving module names and relative paths to full absolute paths. resolvePath uses browser-resolve for node.js module resolution.

  • @param {{ string: name }} input - Object with the property name of the module to be resolved.

  • @param {object} browserResolveOptions - Options to be forwarded to browser-resolve. baseUrl defaults to process.cwd().

  • @returns {Promise} Promise that when resolved it returns an object with a property path for the module.

var resolver = require("bit-bundler-utils/resolvePath");

resolver({
  name: "jquery"
})
.then(function(result) {
  console.log(result.path);
  return result;
});

readFile

Helper method to read files from disk. This method returns promises that when resolved it returns the content of the file. readFile gracefully handles binary files.

  • @param {{ string: path }} input - Object with property path for the file to be loaded from disk.
  • @returns {Promise} That when resolved, returns and object with a string property containing the file content

Example

var readFile = require("bit-bundler-utils/readFile");

readFile({
  path: "./file/path"
})
.then(function(result) {
  console.log(result.source);
  return result;
});

License

Licensed under MIT

Readme

Keywords

Package Sidebar

Install

npm i @bit/bundler-utils

Weekly Downloads

1

Version

5.1.3

License

MIT

Unpacked Size

8.15 kB

Total Files

13

Last publish

Collaborators

  • manchagnu