Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Ecmascript modules #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ os:
language: node_js
node_js:
- node
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
- lts/*
- '12'
- '10'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion benchmark/index.js → benchmark/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*!
* normalize-path <https://github.com/jonschlinkert/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('/');
};
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const normalize: (path: string, stripTrailing?: boolean) => string;

export default normalize;
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

/*!
* normalize-path <https://github.com/jonschlinkert/normalize-path>
*
* Copyright (c) 2014-2018, Jon Schlinkert.
* 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');
}
Expand All @@ -32,4 +33,4 @@ module.exports = function(path, stripTrailing) {
segs.pop();
}
return prefix + segs.join('/');
};
}
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test.js → test/test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down