From 998dcc864a7c36b63cc08b96bdd00e1e861fad34 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 14 Apr 2021 14:06:29 +0700 Subject: [PATCH] Require Node.js 12 and move to ESM --- .github/workflows/main.yml | 4 +--- index.d.ts | 8 +++----- index.js | 5 ++--- index.test-d.ts | 2 +- license | 2 +- package.json | 13 ++++++++----- readme.md | 8 ++------ test.js | 2 +- 8 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..d36e1a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/index.d.ts b/index.d.ts index f9d07d1..10438fb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 @@ -20,6 +20,4 @@ slash(string); // Windows => foo/bar ``` */ -declare function slash(path: string): string; - -export = slash; +export default function slash(path: string): string; diff --git a/index.js b/index.js index 103fbea..b52d8de 100644 --- a/index.js +++ b/index.js @@ -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 @@ -8,4 +7,4 @@ module.exports = path => { } return path.replace(/\\/g, '/'); -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index a38730c..677b5f7 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ import {expectType} from 'tsd'; -import slash = require('.'); +import slash from './index.js'; expectType(slash('foo\\bar')); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (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: diff --git a/package.json b/package.json index c88fcc7..f69a2e9 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" } } diff --git a/readme.md b/readme.md index 8ecb730..2a66eef 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -29,7 +27,6 @@ slash(string); // Windows => foo/bar ``` - ## API ### slash(path) @@ -38,7 +35,6 @@ Type: `string` Accepts a Windows backslash path and returns a path with forward slashes. - ---
diff --git a/test.js b/test.js index 910c2d3..424ca65 100644 --- a/test.js +++ b/test.js @@ -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');