@stryke/path 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/replace.cjs CHANGED
@@ -3,10 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.replaceExtension = replaceExtension;
6
7
  exports.replacePath = replacePath;
7
8
  var _cwd = require("./cwd.cjs");
9
+ var _filePathFns = require("./file-path-fns.cjs");
8
10
  var _isParentPath = require("./is-parent-path.cjs");
9
11
  var _slash = require("./slash.cjs");
10
- function replacePath(r, e = (0, _cwd.cwd)()) {
11
- return (0, _isParentPath.isParentPath)(r, e) ? (0, _slash.slash)(r).replace((0, _slash.slash)(e), "").replace(/^\//, "") : r;
12
+ function replacePath(r, i = (0, _cwd.cwd)()) {
13
+ return (0, _isParentPath.isParentPath)(r, i) ? (0, _slash.slash)(r).replace((0, _slash.slash)(i), "").replace(/^\//, "") : r;
14
+ }
15
+ function replaceExtension(r, i = "") {
16
+ return r.replace(!i || i.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), i);
12
17
  }
package/dist/replace.d.ts CHANGED
@@ -12,3 +12,19 @@
12
12
  * @returns The {@link childPath} with the {@link parentPath} path removed
13
13
  */
14
14
  export declare function replacePath(childPath: string, parentPath?: string): string;
15
+ /**
16
+ * Replace the extension of a given path with the provided value.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * replaceExtension("/home/user/project/src/index.ts", ".js");
21
+ * // returns "/home/user/project/src/index.js"
22
+ * replaceExtension("/home/user/project/src/index.ts");
23
+ * // returns "/home/user/project/src/index"
24
+ * ```
25
+ *
26
+ * @param path - The path that will have its current extension replaced
27
+ * @param replacement - The value (or an empty string) to replace the current extension with
28
+ * @returns The path with the replaced extension
29
+ */
30
+ export declare function replaceExtension(path: string, replacement?: string): string;
package/dist/replace.mjs CHANGED
@@ -1 +1 @@
1
- import{cwd as t}from"./cwd";import{isParentPath as i}from"./is-parent-path";import{slash as o}from"./slash";export function replacePath(r,e=t()){return i(r,e)?o(r).replace(o(e),"").replace(/^\//,""):r}
1
+ import{cwd as e}from"./cwd";import{findFileDotExtensionSafe as o,findFileExtensionSafe as t}from"./file-path-fns";import{isParentPath as s}from"./is-parent-path";import{slash as n}from"./slash";export function replacePath(r,i=e()){return s(r,i)?n(r).replace(n(i),"").replace(/^\//,""):r}export function replaceExtension(r,i=""){return r.replace(!i||i.includes(".")?o(r):t(r),i)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {
@@ -279,5 +279,5 @@
279
279
  "main": "./dist/index.cjs",
280
280
  "module": "./dist/index.mjs",
281
281
  "types": "./dist/index.d.ts",
282
- "gitHead": "c60091277e3643e8619c90a06a9e9aed326359c1"
282
+ "gitHead": "b7c19085be057c7a239682d125c26a6e468c8b9d"
283
283
  }