path#win32 TypeScript Examples
The following examples show how to use
path#win32.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: filesystemPathHandling.ts From telefunc with MIT License | 6 votes |
function toPosixPath(path: string) {
if (process.platform !== 'win32') {
assert(sep === posix.sep)
assertPosixPath(path)
return path
} else {
assert(sep === win32.sep)
const pathPosix = path.split(win32.sep).join(posix.sep)
assertPosixPath(pathPosix)
return pathPosix
}
}
Example #2
Source File: isChildPath.test.ts From backstage with Apache License 2.0 | 5 votes |
describe('isChildPath', () => {
it('should check child posix paths', () => {
jest.isolateModules(() => {
jest.setMock('path', posix);
const { isChildPath } = require('./isChildPath');
expect(isChildPath('/', '/')).toBe(true);
expect(isChildPath('/x', '/x')).toBe(true);
expect(isChildPath('/x', '/x/y')).toBe(true);
expect(isChildPath('/x', '/x/x')).toBe(true);
expect(isChildPath('/x', '/x/y/z')).toBe(true);
expect(isChildPath('/x/y', '/x/y/z')).toBe(true);
expect(isChildPath('/x/y/z', '/x/y/z')).toBe(true);
expect(isChildPath('/x/a b c/z', '/x/a b c/z')).toBe(true);
expect(isChildPath('/', '/ yz')).toBe(true);
expect(isChildPath('/x', '/y')).toBe(false);
expect(isChildPath('/x', '/')).toBe(false);
expect(isChildPath('/x', '/x y')).toBe(false);
expect(isChildPath('/x y', '/x yz')).toBe(false);
expect(isChildPath('/ yz', '/')).toBe(false);
expect(isChildPath('/x', '/')).toBe(false);
jest.dontMock('path');
});
});
it('should check child win32 paths', () => {
jest.isolateModules(() => {
jest.setMock('path', win32);
const { isChildPath } = require('./isChildPath');
expect(isChildPath('/x', '/x')).toBe(true);
expect(isChildPath('/x', '/x/y')).toBe(true);
expect(isChildPath('/x', '/x/x')).toBe(true);
expect(isChildPath('/x', '/x/y/z')).toBe(true);
expect(isChildPath('/x/y', '/x/y/z')).toBe(true);
expect(isChildPath('/x/y/z', '/x/y/z')).toBe(true);
expect(isChildPath('Z:', 'Z:')).toBe(true);
expect(isChildPath('C:/', 'c:/')).toBe(true);
expect(isChildPath('C:/x', 'C:/x')).toBe(true);
expect(isChildPath('C:/x', 'c:/x')).toBe(true);
expect(isChildPath('C:/x', 'C:/x/y')).toBe(true);
expect(isChildPath('d:/x', 'D:/x/y')).toBe(true);
expect(isChildPath('/x', '/y')).toBe(false);
expect(isChildPath('/x', '/')).toBe(false);
expect(isChildPath('C:/', 'D:/')).toBe(false);
expect(isChildPath('C:/x', 'D:/x')).toBe(false);
expect(isChildPath('D:/x', 'CD:/x')).toBe(false);
expect(isChildPath('D:/x', 'D:/y')).toBe(false);
jest.dontMock('path');
});
});
});
Example #3
Source File: assertPosixPath.ts From telefunc with MIT License | 5 votes |
function assertPosixPath(path: string) {
const errMsg = `Wrongly formatted path: ${path}`
assert(!path.includes(win32.sep), errMsg)
// assert(path.startsWith('/'), errMsg)
}
Example #4
Source File: filesystemPathHandling.ts From telefunc with MIT License | 5 votes |
function toSystemPath(path: string) {
path = path.split(posix.sep).join(sep)
path = path.split(win32.sep).join(sep)
return path
}