Skip to content

Commit

Permalink
Merge pull request #168 from cginternals/remove-path-110
Browse files Browse the repository at this point in the history
#110 remove use of nodejs path, tweak example
  • Loading branch information
cgcostume committed Mar 8, 2019
2 parents 2d1c3f1 + fecd829 commit f328bca
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/labelanchor-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ export class LabelAnchorExample extends Example {
this._canvas.renderer = this._renderer;

// Create some horizontal rules/lines as reference for the different anchors.
const hrStyle = 'z-index: 1; position: absolute; width: 99%; margin: 0;'
+ 'border-color: #27aae1; border-style: dashed; border-width: 1px;';
const hrStyle = 'z-index: 1; position: absolute; width: 98%; margin: 0; margin-left: 1%;'
+ 'border: none; border-top: 1pt solid #1c75bc;';

const hr0 = document.createElement('hr');
hr0.setAttribute('style', `${hrStyle} top: 8.3333%;`);
Expand Down
27 changes: 27 additions & 0 deletions source/auxiliaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,33 @@ namespace auxiliaries {
return match[1];
}

/**
* Path separator used for path related functions such as dirname and basename.
*/
export const PATH_SEPARATOR = '/';

/**
* Returns the directory name of a given (file) path. If no path separator is found, an empty dir name is returned.
* @param path - Path string the directory name should be returned of.
*/
export function dirname(path: string): string {
if (path.includes(PATH_SEPARATOR) === false) {
return '';
}
return path.substr(0, path.lastIndexOf(PATH_SEPARATOR)).trimLeft();
}

/**
* Returns the base name of a given file path. If no path separator is found, the input path is returned.
* @param path - Path string the file/base name should be returned of.
*/
export function basename(path: string): string {
if (path.includes(PATH_SEPARATOR) === false) {
return path;
}
return path.substr(path.lastIndexOf(PATH_SEPARATOR) + 1).trimRight();
}

}

export = auxiliaries;
8 changes: 2 additions & 6 deletions source/text/fontfaceloader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/* spellchecker: disable */

import { log, logIf, LogLevel } from '../auxiliaries';
import { dirname, log, logIf, LogLevel } from '../auxiliaries';
import { GLfloat2, GLfloat4 } from '../tuples';

import { FontFace } from './fontface';
Expand All @@ -10,10 +10,6 @@ import { Glyph } from './glyph';
/* spellchecker: enable */


/** @todo replace path */
import Path = require('path');


type StringPairs = Map<string, string>;

/**
Expand Down Expand Up @@ -102,7 +98,7 @@ export class FontFaceLoader {
return undefined;
}

const path = Path.dirname(url);
const path = dirname(url);
let page = pairs.get('file')!;
page = page.replace(/['"]+/g, ''); /* remove quotes */

Expand Down
21 changes: 21 additions & 0 deletions test/auxiliaries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,24 @@ describe('auxiliaries GETparameter', () => {
// });

});


describe('auxiliaries path', () => {

it('should return the directory name of a file path', () => {
expect(aux.dirname('https://localhost/file.ext')).to.equal('https://localhost');
expect(aux.dirname('file.ext')).to.equal('');

expect(aux.dirname('localhost/file')).to.equal('localhost');
expect(aux.dirname('localhost/dir/')).to.equal('localhost/dir');
});

it('should return the base name of a file path', () => {
expect(aux.basename('https://localhost/file.ext')).to.equal('file.ext');
expect(aux.basename('file.ext')).to.equal('file.ext');

expect(aux.basename('localhost/file')).to.equal('file');
expect(aux.basename('localhost/dir/')).to.equal('');
});

});

0 comments on commit f328bca

Please sign in to comment.