Repository: char0n/ramda-adjunct
Pull request #1619 (2020-10-07 05:04:07)

chore(deps-dev): bump sinon from 9.1.0 to 9.2.0
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.1.0 to 9.2.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md">sinon's changelog</a>.</em></p>
<blockquote>
<h1>9.2.0 / 2020-10-06</h1>
<ul>
<li>Update dependencies (<a href="https://github-redirect.dependabot.com/sinonjs/sinon/issues/2299">#2299</a>)</li>
<li>Update sandbox docs with missing comma</li>
<li>Add minor markdown formatting to release docs for sandbox</li>
<li>Minor formatting improvements to legacy sandbox documentation</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/sinonjs/sinon/commit/077616cc5f7a4659fdbdeff0a83e9ffa087aa8a5"><code>077616c</code></a> 9.2.0</li>
<li><a href="https://github.com/sinonjs/sinon/commit/3ab90b9a16e570935131799852df9ef3ae37c070"><code>3ab90b9</code></a> Update CHANGELOG.md and AUTHORS for new release</li>
<li><a href="https://github.com/sinonjs/sinon/commit/0f913572fce46d351f137f1522f945f1c2539cf5"><code>0f91357</code></a> Run npm dedupe to get rid of duplicate @sinonjs/samsam</li>
<li><a href="https://github.com/sinonjs/sinon/commit/fb91152b131556dac0e1a65d29d0902a03b8c906"><code>fb91152</code></a> Update dependencies (<a href="https://github-redirect.dependabot.com/sinonjs/sinon/issues/2299">#2299</a>)</li>
<li><a href="https://github.com/sinonjs/sinon/commit/e09ee6152405c49fc48fb8dc887847f811bc02c7"><code>e09ee61</code></a> Update sandbox docs with missing comma</li>
<li><a href="https://github.com/sinonjs/sinon/commit/b393422e75e9efb526551dbd246200cdea947dc3"><code>b393422</code></a> Add minor markdown formatting to release docs for sandbox</li>
<li><a href="https://github.com/sinonjs/sinon/commit/e27727acf5facd5d287f1e2665d9272f9d9e3651"><code>e27727a</code></a> Minor formatting improvements to legacy sandbox documenation</li>
<li><a href="https://github.com/sinonjs/sinon/commit/0eed0af32affd8741ab26878b2add22ec6da7285"><code>0eed0af</code></a> Update docs/changelog.md and set new release id in docs/_config.yml</li>
<li><a href="https://github.com/sinonjs/sinon/commit/7eeec0139c136a1e449fc6aa6eb58526b55f1a78"><code>7eeec01</code></a> Add release documentation for v9.1.0</li>
<li>See full diff in <a href="https://github.com/sinonjs/sinon/compare/v9.1.0...v9.2.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=sinon&package-manager=npm_and_yarn&previous-version=9.1.0&new-version=9.2.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/configuring-github-dependabot-security-updates)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

char0n: @dependabot rebase

Patch:
diff --git a/package-lock.json b/package-lock.json
index 8caee0723c..972b42e2cf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3101,9 +3101,9 @@
       }
     },
     "@sinonjs/samsam": {
-      "version": "5.1.0",
-      "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.1.0.tgz",
-      "integrity": "sha512-42nyaQOVunX5Pm6GRJobmzbS7iLI+fhERITnETXzzwDZh+TtDr/Au3yAvXVjFmZ4wEUaE4Y3NFZfKv0bV0cbtg==",
+      "version": "5.2.0",
+      "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.2.0.tgz",
+      "integrity": "sha512-CaIcyX5cDsjcW/ab7HposFWzV1kC++4HNsfnEdFJa7cP1QIuILAKV+BgfeqRXhcnSAc76r/Rh/O5C+300BwUIw==",
       "dev": true,
       "requires": {
         "@sinonjs/commons": "^1.6.0",
@@ -14653,15 +14653,15 @@
       "dev": true
     },
     "sinon": {
-      "version": "9.1.0",
-      "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.1.0.tgz",
-      "integrity": "sha512-9zQShgaeylYH6qtsnNXlTvv0FGTTckuDfHBi+qhgj5PvW2r2WslHZpgc3uy3e/ZAoPkqaOASPi+juU6EdYRYxA==",
+      "version": "9.2.0",
+      "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.0.tgz",
+      "integrity": "sha512-eSNXz1XMcGEMHw08NJXSyTHIu6qTCOiN8x9ODACmZpNQpr0aXTBXBnI4xTzQzR+TEpOmLiKowGf9flCuKIzsbw==",
       "dev": true,
       "requires": {
-        "@sinonjs/commons": "^1.7.2",
+        "@sinonjs/commons": "^1.8.1",
         "@sinonjs/fake-timers": "^6.0.1",
         "@sinonjs/formatio": "^5.0.1",
-        "@sinonjs/samsam": "^5.1.0",
+        "@sinonjs/samsam": "^5.2.0",
         "diff": "^4.0.2",
         "nise": "^4.0.4",
         "supports-color": "^7.1.0"
diff --git a/package.json b/package.json
index 061da285b4..e53d1fec31 100644
--- a/package.json
+++ b/package.json
@@ -183,7 +183,7 @@
     "ramda-fantasy": "=0.8.0",
     "rimraf": "3.0.2",
     "sanctuary-show": "2.0.0",
-    "sinon": "9.1.0",
+    "sinon": "9.2.0",
     "terser-webpack-plugin": "4.2.3",
     "testem": "=3.2.0",
     "tslint": "=6.1.3",
diff --git a/src/index.js b/src/index.js
index cb3a54b746..cb3d694b13 100644
--- a/src/index.js
+++ b/src/index.js
@@ -159,6 +159,7 @@ export { default as invokeArgs } from './invokeArgs';
 export { default as paths } from './paths';
 export { default as renameKeys } from './renameKeys';
 export { default as renameKeysWith } from './renameKeysWith';
+export { default as renameKeyWith } from './renameKeyWith';
 export { default as mergeRight } from './mergeRight';
 export { default as mergeLeft } from './mergeRight';
 export { default as resetToDefault } from './mergeRight';
diff --git a/src/renameKeyWith.js b/src/renameKeyWith.js
new file mode 100644
index 0000000000..539aadfd75
--- /dev/null
+++ b/src/renameKeyWith.js
@@ -0,0 +1,30 @@
+import { curry, equals, when } from 'ramda';
+
+import renameKeysWith from './renameKeysWith';
+
+/**
+ * Creates a new object with the own properties of the provided object, but the
+ * key `key` renamed according to logic of renaming function.
+ *
+ * Keep in mind that in case the new key name already existed on the object,
+ * the behaviour is undefined and the result may vary between various JS engines!
+ *
+ * @func renameKeyWith
+ * @memberOf RA
+ * @since {@link https://char0n.github.io/ramda-adjunct/2.29.0|v2.29.0}
+ * @category Object
+ * @sig (k -> k) -> k -> {k: v} -> {k: v}
+ * @param {Function} fn Function that renames the keys
+ * @param {!string} key Key to rename
+ * @param {!Object} obj Provided object
+ * @return {!Object} New object with renamed key
+ * @see {@link RA.renameKeysWith|renameKeysWith}
+ * @example
+ *
+ * RA.renameKeyWith(R.concat('a'), 'A', { A: 1 }) //=> { aA: 1 }
+ */
+const renameKeyWith = curry((fn, key, obj) =>
+  renameKeysWith(when(equals(key), fn), obj)
+);
+
+export default renameKeyWith;
diff --git a/types/index.d.ts b/types/index.d.ts
index a1c91709e4..96cb6e9b10 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -561,6 +561,26 @@ declare namespace RamdaAdjunct {
         renameKeysWith(renameFn: (key: string) => string, obj: object): object;
         renameKeysWith(renameFn: (key: string) => string): (obj: object) => object;
 
+        /**
+         * Creates a new object with the own properties of the provided object, but the
+         * key `key` renamed according to logic of renaming function.
+         */
+        renameKeyWith(
+            renameFn: (key: string) => string,
+            key: string,
+            obj: object
+        ): object;
+        renameKeyWith(
+            renameFn: (key: string) => string,
+            key: string
+        ): (obj: object) => object;
+        renameKeyWith(
+            renameFn: (key: string) => string
+        ): {
+            (key: string, obj: object): object;
+            (key: string): (obj: object) => object;
+        };
+
         /**
          * Create a new object with the own properties of the second object merged with
          * the own properties of the first object. If a key exists in both objects,


Test patch:
diff --git a/test/renameKeyWith.js b/test/renameKeyWith.js
new file mode 100644
index 0000000000..9b1f2f71e1
--- /dev/null
+++ b/test/renameKeyWith.js
@@ -0,0 +1,42 @@
+import { assert } from 'chai';
+import { concat } from 'ramda';
+
+import * as RA from '../src';
+
+describe('renameKeyWith', function () {
+  it('should rename object keys', function () {
+    assert.deepEqual(RA.renameKeyWith(concat('a'), 'A', { A: 1 }), {
+      aA: 1,
+    });
+  });
+
+  it('should not change other key-value pairs', function () {
+    assert.deepEqual(RA.renameKeyWith(concat('a'), 'A', { A: 1, B: 2 }), {
+      aA: 1,
+      B: 2,
+    });
+  });
+
+  it('should return an empty object when renames keys on null and undefined', function () {
+    assert.deepEqual(RA.renameKeyWith(concat('a'), 'A', null), {});
+    assert.deepEqual(RA.renameKeyWith(concat('a'), 'A', undefined), {});
+  });
+
+  it('should return the original object when renaming a non-existant key', function () {
+    assert.deepEqual(RA.renameKeyWith(concat('a'), 'B', { A: 1 }), {
+      A: 1,
+    });
+  });
+
+  it('should be curried', function () {
+    assert.deepEqual(RA.renameKeyWith(concat('a'))('A')({ A: 1 }), {
+      aA: 1,
+    });
+    assert.deepEqual(RA.renameKeyWith(concat('a'), 'A')({ A: 1 }), {
+      aA: 1,
+    });
+    assert.deepEqual(RA.renameKeyWith(concat('a'))('A', { A: 1 }), {
+      aA: 1,
+    });
+  });
+});
diff --git a/types/test/renameKeyWith.ts b/types/test/renameKeyWith.ts
new file mode 100644
index 0000000000..a224334159
--- /dev/null
+++ b/types/test/renameKeyWith.ts
@@ -0,0 +1,10 @@
+import * as RA from 'ramda-adjunct';
+
+RA.renameKeyWith((str) => 'a' + str, 'A', { A: 1 }); // $ExpectType object
+RA.renameKeyWith((str) => 'a' + str)('A', { A: 1 }); // $ExpectType object
+RA.renameKeyWith((str) => 'a' + str)('A')({ A: 1 }); // $ExpectType object
+RA.renameKeyWith((str) => 'a' + str, 'A')({ A: 1 }); // $ExpectType object
+
+RA.renameKeyWith((str) => 1, 'A', { A: 1 }); // $ExpectError
+RA.renameKeyWith((str) => 'a' + str, 1, { A: 1 }); // $ExpectError
+RA.renameKeyWith((str) => 'a' + str, 'A', 1); // $ExpectError