diff --git a/.travis.yml b/.travis.yml index 1686664..c7f2be8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,6 @@ os: language: node_js node_js: - node - - '9' - - '8' - - '7' - - '6' - - '5' - - '4' - - '0.12' - - '0.10' + - lts/* + - '12' + - '10' \ No newline at end of file diff --git a/benchmark/code/current.js b/benchmark/code/current.cjs similarity index 100% rename from benchmark/code/current.js rename to benchmark/code/current.cjs diff --git a/benchmark/code/no-regex.js b/benchmark/code/no-regex.cjs similarity index 100% rename from benchmark/code/no-regex.js rename to benchmark/code/no-regex.cjs diff --git a/benchmark/code/node-path.js b/benchmark/code/node-path.cjs similarity index 100% rename from benchmark/code/node-path.js rename to benchmark/code/node-path.cjs diff --git a/benchmark/code/regex.js b/benchmark/code/regex.cjs similarity index 100% rename from benchmark/code/regex.js rename to benchmark/code/regex.cjs diff --git a/benchmark/code/split.js b/benchmark/code/split.cjs similarity index 100% rename from benchmark/code/split.js rename to benchmark/code/split.cjs diff --git a/benchmark/code/v2.js b/benchmark/code/v2.cjs similarity index 100% rename from benchmark/code/v2.js rename to benchmark/code/v2.cjs diff --git a/benchmark/code/while.js b/benchmark/code/while.cjs similarity index 100% rename from benchmark/code/while.js rename to benchmark/code/while.cjs diff --git a/benchmark/fixtures/long.js b/benchmark/fixtures/long.cjs similarity index 100% rename from benchmark/fixtures/long.js rename to benchmark/fixtures/long.cjs diff --git a/benchmark/fixtures/short.js b/benchmark/fixtures/short.cjs similarity index 100% rename from benchmark/fixtures/short.js rename to benchmark/fixtures/short.cjs diff --git a/benchmark/fixtures/single.js b/benchmark/fixtures/single.cjs similarity index 100% rename from benchmark/fixtures/single.js rename to benchmark/fixtures/single.cjs diff --git a/benchmark/fixtures/trailing.js b/benchmark/fixtures/trailing.cjs similarity index 100% rename from benchmark/fixtures/trailing.js rename to benchmark/fixtures/trailing.cjs diff --git a/benchmark/fixtures/unix.js b/benchmark/fixtures/unix.cjs similarity index 100% rename from benchmark/fixtures/unix.js rename to benchmark/fixtures/unix.cjs diff --git a/benchmark/fixtures/win.js b/benchmark/fixtures/win.cjs similarity index 100% rename from benchmark/fixtures/win.js rename to benchmark/fixtures/win.cjs diff --git a/benchmark/fixtures/win32-namespace.js b/benchmark/fixtures/win32-namespace.cjs similarity index 100% rename from benchmark/fixtures/win32-namespace.js rename to benchmark/fixtures/win32-namespace.cjs diff --git a/benchmark/index.js b/benchmark/index.cjs similarity index 78% rename from benchmark/index.js rename to benchmark/index.cjs index 041d09c..6ee2393 100644 --- a/benchmark/index.js +++ b/benchmark/index.cjs @@ -5,7 +5,7 @@ const suite = require('benchmarked'); const argv = process.argv.slice(2); const code = argv[0] || '{current,v2}'; -suite.run({ code: `code/${code}.js`, fixtures: 'fixtures/*.js' }) +suite.run({ code: `code/${code}.cjs`, fixtures: 'fixtures/*.cjs' }) .then(function(stats) { console.log(suite.render(stats)); }) diff --git a/example.js b/example.cjs similarity index 100% rename from example.js rename to example.cjs diff --git a/index.cjs b/index.cjs new file mode 100644 index 0000000..6fac553 --- /dev/null +++ b/index.cjs @@ -0,0 +1,35 @@ +/*! + * normalize-path + * + * Copyright (c) 2014-2018, Jon Schlinkert. + * Released under the MIT License. + */ + +module.exports = function(path, stripTrailing) { + if (typeof path !== 'string') { + throw new TypeError('expected path to be a string'); + } + + if (path === '\\' || path === '/') return '/'; + + var len = path.length; + if (len <= 1) return path; + + // ensure that win32 namespaces has two leading slashes, so that the path is + // handled properly by the win32 version of path.parse() after being normalized + // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces + var prefix = ''; + if (len > 4 && path[3] === '\\') { + var ch = path[2]; + if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') { + path = path.slice(2); + prefix = '//'; + } + } + + var segs = path.split(/[/\\]+/); + if (stripTrailing !== false && segs[segs.length - 1] === '') { + segs.pop(); + } + return prefix + segs.join('/'); +}; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..bedccf0 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +declare const normalize: (path: string, stripTrailing?: boolean) => string; + +export default normalize; \ No newline at end of file diff --git a/index.js b/index.js index 6fac553..64eb781 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ + /*! * normalize-path * @@ -5,7 +6,7 @@ * Released under the MIT License. */ -module.exports = function(path, stripTrailing) { +export default function(path, stripTrailing) { if (typeof path !== 'string') { throw new TypeError('expected path to be a string'); } @@ -32,4 +33,4 @@ module.exports = function(path, stripTrailing) { segs.pop(); } return prefix + segs.join('/'); -}; +} diff --git a/package.json b/package.json index ad61098..28e586f 100644 --- a/package.json +++ b/package.json @@ -8,25 +8,33 @@ "Blaine Bublitz (https://twitter.com/BlaineBublitz)", "Jon Schlinkert (http://twitter.com/jonschlinkert)" ], - "repository": "jonschlinkert/normalize-path", + "repository": "https://github.com/jonschlinkert/normalize-path", "bugs": { "url": "https://github.com/jonschlinkert/normalize-path/issues" }, "license": "MIT", "files": [ - "index.js" + "index.js", + "index.cjs" ], - "main": "index.js", + "main": "index.cjs", + "exports": { + "import": "./index.js", + "require": "./index.cjs" + }, + "type": "module", + "typing": "index.d.ts", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, + "dependencies": {}, "devDependencies": { - "gulp-format-md": "^1.0.0", - "minimist": "^1.2.0", - "mocha": "^3.5.3" + "gulp-format-md": "^2.0.0", + "minimist": "^1.2.5", + "mocha": "^8.2.1" }, "keywords": [ "absolute", diff --git a/test.js b/test/test.cjs similarity index 98% rename from test.js rename to test/test.cjs index 55b3bda..6a7c5a9 100644 --- a/test.js +++ b/test/test.cjs @@ -11,7 +11,7 @@ require('mocha'); var path = require('path'); var argv = require('minimist')(process.argv.slice(2)); var assert = require('assert'); -var normalize = require('./'); +var normalize = require('../'); if (argv.bench) { var b = path.join(__dirname, 'benchmark/code', argv.bench);