-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
utils.js
47 lines (43 loc) · 1.05 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const path = require(`path`)
const Url = require(`url`)
const { createFilePath } = require(`gatsby-core-utils`)
/**
* getParsedPath
* --
* Parses remote url to a path object
*
*
* @param {String} url
* @return {Object} path
*/
function getParsedPath(url) {
return path.parse(Url.parse(url).pathname)
}
/**
* getRemoteFileExtension
* --
* Parses remote url to retrieve remote file extension
*
*
* @param {String} url
* @return {String} extension
*/
export function getRemoteFileExtension(url) {
return getParsedPath(url).ext
}
/**
* getRemoteFileName
* --
* Parses remote url to retrieve remote file name
*
*
* @param {String} url
* @return {String} filename
*/
export function getRemoteFileName(url) {
return decodeURIComponent(getParsedPath(url).name)
}
// createFilePath should be imported from `gatsby-core-utils`
// but some plugins already do import it from `gatsby-source-filesystem/utils`
// so just keeping re-export here for backward compatibility
export { createFilePath }