Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104934644
getInfoFromHash.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Mar 13, 12:00
Size
1 KB
Mime Type
text/x-java
Expires
Sat, Mar 15, 12:00 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
24883268
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
getInfoFromHash.js
View Options
import "core-js/modules/es.array.filter";
import "core-js/modules/es.regexp.exec";
import "core-js/modules/es.string.match";
import { hasInHash, getHashAsArray } from './handleHash';
function hasDigitsOnly(item) {
return item.match(/^\d+$/) !== null;
}
/**
* Returns an object containing component/section name and, optionally, an example index
* from hash part or page URL:
* #!/Button → { targetName: 'Button' }
* #!/Button/1 → { targetName: 'Button', targetIndex: 1 }
*
* @param {string} hash
* @returns {object}
*/
export default function getInfoFromHash(hash) {
var shouldIsolate = hasInHash(hash, '#!/');
if (shouldIsolate || hasInHash(hash, '#/')) {
var hashArray = getHashAsArray(hash, shouldIsolate ? '#!/' : '#/');
var targetHash = hashArray[hashArray.length - 1];
return {
isolate: shouldIsolate,
hashArray: hashArray.filter(function (item) {
return !hasDigitsOnly(item);
}),
targetName: hashArray[0],
targetIndex: hasDigitsOnly(targetHash) ? parseInt(targetHash, 10) : undefined
};
}
return {};
}
Event Timeline
Log In to Comment