Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuaz committed Jun 9, 2022
1 parent 17212c2 commit 264abc5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/interpolateName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function interpolateName(
let resourcePath = loaderResourcePath

if (parsed.ext) {
ext = parsed.ext.substr(1)
ext = parsed.ext.slice(1)
}

if (parsed.dir) {
Expand All @@ -41,7 +41,7 @@ export default function interpolateName(
.relative(context, resourcePath + '_')
.replace(/\\/g, '/')
.replace(/\.\.(\/)?/g, '_$1')
directory = directory.substr(0, directory.length - 1)
directory = directory.slice(0, directory.length - 1)
} else {
directory = resourcePath.replace(/\\/g, '/').replace(/\.\.(\/)?/g, '_$1')
}
Expand All @@ -59,7 +59,7 @@ export default function interpolateName(
const hashIdx = query.indexOf('#')

if (hashIdx >= 0) {
query = query.substr(0, hashIdx)
query = query.slice(0, hashIdx)
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,9 @@ const getOutputAndPublicPath: GetOutputAndPublicPath = (
if (configPublicPath) {
if (typeof configPublicPath === 'function') {
publicPath = configPublicPath(fileName)
} else if (configPublicPath.endsWith('/')) {
publicPath = configPublicPath + fileName
} else {
publicPath = `${configPublicPath}/${fileName}`
publicPath = path.posix.join(configPublicPath, fileName)
}

publicPath = JSON.stringify(publicPath)
}

Expand Down
12 changes: 12 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getOutputAndPublicPath } from '../lib/utils'

describe('Utils package', () => {
it('should create both paths', () => {
const { outputPath, publicPath } = getOutputAndPublicPath('file.png', {
outputPath: '/dist/img/',
publicPath: '/img',
})
expect(outputPath).toBe('/dist/img/file.png')
expect(publicPath).toBe('"/img/file.png"')
})
})

0 comments on commit 264abc5

Please sign in to comment.