UNPKG

synapse_fs

Version:
41 lines (34 loc) 1.68 kB
var path = require('path'); var S = require('string'); function File (options) { //We're using the absolute file name as unique id. CSS doesn't support slashes and Full Stops as part of the selector name, so we have to convert them //Forward slash becomes underscore (_) //Full Stop becomes hyphen (-) var fsSeperator = '/'; //fs seperator is not OS specific. It's always a forward slash if (options.absoluteFileName == fsSeperator)//If it's the root (special case) this.id = options.absoluteFileName.replace(fsSeperator,'__root__'); else { var id = options.absoluteFileName.replace(root, ''); this.id = S(id).replaceAll(fsSeperator, '_').s; this.id = S(this.id).replaceAll('.', '-').s; } this.rootSearchPath = options.rootSearchPath; this.depthCountOffset = S(S(S(options.absoluteFileName).replaceAll(this.rootSearchPath, ''))).count(fsSeperator); if (this.rootSearchPath.indexOf('//') == 0) this.depthCount = S(options.absoluteFileName.substring(2)).count(fsSeperator); else if (this.rootSearchPath.indexOf('/') == 0) this.depthCount = S(options.absoluteFileName.substring(1)).count(fsSeperator); else if (this.rootSearchPath.indexOf('./') == 0) this.depthCount = S(options.absoluteFileName.substring(2)).count(fsSeperator); else if (this.rootSearchPath.indexOf('.//') == 0) this.depthCount = S(options.absoluteFileName.substring(3)).count(fsSeperator); this.absoluteFileName = options.absoluteFileName; this.fileName = options.fileName; this.isFile = options.isFile; this.isDirectory = options.isDirectory; this.error = options.error; }; File.prototype.constructor = File; module.exports = File;