UNPKG

hbp-react-ui

Version:

A library of useful user-interface components built with React and MobX

40 lines (36 loc) 9.9 kB
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}} /** * Path breaks down the supplied path into the underlying elements. * @param {string} path The path to an element in a JSON structure e.g. '/Category/Item' * @returns {object} An object that can be queried for individual elements * @todo * Needs to work for all the below i.e unit test * /SpecimenGroup/Subjects/0/Samples/0/ParcellationAtlas * /SpecimenGroup/Subjects/0/Sex * /SpecimenGroup/Subjects * /SpecimenGroup */var Path = function () { function Path(path) {_classCallCheck(this, Path); try { this.path = path; this.matches = this.path.match(/^\/([\w-]+)(?:.*\/([\w-]+))?/); // This isn't correct } catch (error) { console.log('Path.constructor: ' + error.message); } }_createClass(Path, [{ key: 'value', get: function get() { return this.path; } }, { key: 'first', get: function get() { if (this.matches.length > 1) { return this.matches[1]; } } }, { key: 'last', get: function get() { if (this.matches.length > 2) { return this.matches[this.matches.length - 1]; } } }, { key: 'length', get: function get() { return this.matches.length - 1; // The number of path elements } }]);return Path;}();exports.default = Path;