Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 14, 2021
1 parent 617a904 commit 998dcc8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 25 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
8 changes: 3 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Convert Windows backslash paths to slash paths: `foo\\bar` ➔ `foo/bar`.
@example
```
import * as path from 'path';
import slash = require('slash');
import path from 'path';
import slash from 'slash';
const string = path.join('foo', 'bar');
// Unix => foo/bar
Expand All @@ -20,6 +20,4 @@ slash(string);
// Windows => foo/bar
```
*/
declare function slash(path: string): string;

export = slash;
export default function slash(path: string): string;
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
module.exports = path => {
export default function slash(path) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex

Expand All @@ -8,4 +7,4 @@ module.exports = path => {
}

return path.replace(/\\/g, '/');
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import slash = require('.');
import slash from './index.js';

expectType<string>(slash('foo\\bar'));
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Convert Windows backslash paths to slash paths",
"license": "MIT",
"repository": "sindresorhus/slash",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -28,8 +31,8 @@
"convert"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
8 changes: 2 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@

This was created since the `path` methods in Node.js outputs `\\` paths on Windows.


## Install

```
$ npm install slash
```


## Usage

```js
const path = require('path');
const slash = require('slash');
import path from 'path';
import slash from 'slash';

const string = path.join('foo', 'bar');
// Unix => foo/bar
Expand All @@ -29,7 +27,6 @@ slash(string);
// Windows => foo/bar
```


## API

### slash(path)
Expand All @@ -38,7 +35,6 @@ Type: `string`

Accepts a Windows backslash path and returns a path with forward slashes.


---

<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import slash from '.';
import slash from './index.js';

test('convert backwards-slash paths to forward slash paths', t => {
t.is(slash('c:/aaaa\\bbbb'), 'c:/aaaa/bbbb');
Expand Down

0 comments on commit 998dcc8

Please sign in to comment.