2
0
mirror of https://github.com/iconify/collections-json.git synced 2024-11-08 22:31:06 +00:00
iconify-collections-json/lib/finder.js
2018-10-21 14:20:25 +03:00

50 lines
1.1 KiB
JavaScript

/**
* This file is part of the iconify.design libraries.
*
* (c) Vjacheslav Trushkin <cyberalien@gmail.com>
*
* @license MIT
*
* For the full copyright and license information, please view the license.txt
* file that is available in this file's directory.
*/
"use strict";
const path = require('path');
const fs = require('fs');
const dir = path.dirname(__dirname);
module.exports = {
/**
* Get root directory of this package
* (not really useful in Node.js because require can do it, but added anyway to match php code)
*
* @returns {string}
*/
rootDir: () => dir,
/**
* Locate JSON file
*
* @param {string} name Collection name
* @returns {string} Path to collection json file
*/
locate: name => dir + '/json/' + name + '.json',
/**
* Get list of collections
*
* @return {object|null}
*/
collections: () => {
try {
let data = fs.readFileSync(dir + '/collections.json', 'utf8');
data = JSON.parse(data);
return data;
} catch (err) {
return null;
}
}
};