You are here

function libraries_get_package_json_version in Libraries API 7.2

Gets the version information from a library's package.json file.

Parameters

$library: An associative array containing all information about the library.

$options: This callback expects no option.

Return value

A string containing the version of the library.

See also

libraries_get_path()

File

./libraries.module, line 980
External library handling for Drupal modules.

Code

function libraries_get_package_json_version($library, $options) {
  $file = DRUPAL_ROOT . '/' . $library['library path'] . '/package.json';
  if (!file_exists($file)) {
    return;
  }
  $content = file_get_contents($file);
  if (!$content) {
    return;
  }
  $data = drupal_json_decode($content);
  if (isset($data['version'])) {
    return $data['version'];
  }
}