Repository: char0n/ramda-adjunct
Pull request #1254 (2020-01-06 14:26:08)

feat: add trimCharsStart
#1135 

Add trimCharsStart function / types / tests. Happy to receive any feedback 🙇 


kitasuna: Thanks very much for the quick review and feedback! I've attempted to address your comments, and committed the suggestions you left as well.
kitasuna: Not sure what to make of this message from CI:

```
not ok 3133 Chrome - [undefined ms] - error
    ---
        message: >
            Error: Browser timeout exceeded: 10s
            Stderr: 
             Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
            [8840:8877:0107/143103.038344:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
            [8840:8971:0107/143103.120100:ERROR:bus.cc(393)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
            ATTENTION: default value of option force_s3tc_enable overridden by environment.
            
            (google-chrome:8840): LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Unknown or unsupported transport 'disabled' for address 'disabled:'
            [8891:8891:0107/143103.170580:ERROR:sandbox_linux.cc(368)] InitializeSandbox() called with multiple threads in process gpu-process.
            [8985:9014:0107/143103.184619:ERROR:command_buffer_proxy_impl.cc(126)] ContextResult::kTransientFailure: Failed to send GpuChannelMsg_CreateCommandBuffer.
            
            
        browser log: |
            [object Object]
            [object Object]
    ...
```
char0n: @kitasuna I've restarted the tests. This sometimes happens. Some internals of CircleCI fails and it reports as false positive. Should be ok after tests finish running. 
kitasuna: @char0n I moved the curry test to the end and rebased. Thanks for the guidance in getting this up to snuff! It's been fun to work on.
char0n: > I moved the curry test to the end and rebased

@kitasuna, thank you! Next time no need for you to rebase, GitHub has a feature `Squash and merge` that allows me to squash and merge your PR it into single commit. In past the contributors were required to rebase to clean up the PR, but it's no longer required as I can do it before the merge itself directly on Github webpage.

> Thanks for the guidance in getting this up to snuff! It's been fun to work on.

My pleasure! In future if you want to continue with work here take a look at all the [issues you could implement](https://github.com/char0n/ramda-adjunct/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22help+wanted%22+label%3Afeature). Maybe some of them will interest you.

Patch:
diff --git a/src/index.js b/src/index.js
index fb9ecca516..24a7e82b6e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -202,6 +202,7 @@ export { default as trimStart } from './trimStart';
 export { default as trimLeft } from './trimStart'; // alias of trimStart
 export { default as trimEnd } from './trimEnd';
 export { default as trimRight } from './trimEnd'; // alias of trimEnd
+export { default as trimCharsStart } from './trimCharsStart';
 export { default as padCharsStart } from './padCharsStart';
 export { default as padCharsEnd } from './padCharsEnd';
 export { default as padEnd } from './padEnd';
diff --git a/src/trimCharsStart.js b/src/trimCharsStart.js
new file mode 100644
index 0000000000..50c66614d4
--- /dev/null
+++ b/src/trimCharsStart.js
@@ -0,0 +1,25 @@
+import { curry, dropWhile, join, pipe, split } from 'ramda';
+
+import contained from './contained';
+
+/**
+ * Removes leading specified characters from string.
+ *
+ * @func trimCharsStart
+ * @memberOf RA
+ * @since {@link https://char0n.github.io/ramda-adjunct/2.24.0|v2.24.0}
+ * @category String
+ * @sig String -> String
+ * @param {string} chars The characters to trim
+ * @param {string} value The characters to trim
+ * @return {string} Returns the trimmed string.
+ * @example
+ *
+ * RA.trimCharsStart('_-', '-_-abc-_-'); //=> 'abc-_-'
+ */
+
+const trimCharsStart = curry((chars, value) =>
+  pipe(split(''), dropWhile(contained(chars)), join(''))(value)
+);
+
+export default trimCharsStart;
diff --git a/types/index.d.ts b/types/index.d.ts
index e2305a315b..28b3151a73 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -1294,6 +1294,12 @@ declare namespace RamdaAdjunct {
         trimEnd(value: string): string;
         trimRight(value: string): string;
 
+        /**
+         * Removes leading specified characters from string.
+         */
+        trimCharsStart(chars: string, value: string): string;
+        trimCharsStart(chars: string): (value: string) => string;
+
         /**
          * The function pads the current string with a given string
          * (repeated, if needed) so that the resulting string reaches a given length.


Test patch:
diff --git a/test/trimCharsStart.js b/test/trimCharsStart.js
new file mode 100644
index 0000000000..d8e3a5dae6
--- /dev/null
+++ b/test/trimCharsStart.js
@@ -0,0 +1,49 @@
+import { assert } from 'chai';
+
+import * as RA from '../src';
+
+describe('trimCharsStart', function() {
+  it('should remove all occurences of a trim character', function() {
+    assert.strictEqual(RA.trimCharsStart('-', '---abc'), 'abc');
+  });
+
+  it('should remove all occurences of all trim characters', function() {
+    assert.strictEqual(RA.trimCharsStart('_-', '-_-abc'), 'abc');
+  });
+
+  it('should not remove the trim characters from the end of the string', function() {
+    assert.strictEqual(RA.trimCharsStart('_-', '-_-abc-_-'), 'abc-_-');
+  });
+
+  context('given none of the trim characters are present', function() {
+    specify('should return the target string as-is', function() {
+      assert.strictEqual(RA.trimCharsStart('_-', 'abc'), 'abc');
+    });
+  });
+
+  context(
+    'given the target string consists entirely of trim characters',
+    function() {
+      specify('should return an empty string', function() {
+        assert.strictEqual(RA.trimCharsStart('_-', '-_-_-_'), '');
+      });
+    }
+  );
+
+  context('given an empty string for the trim characters', function() {
+    specify('should return the target string as-is', function() {
+      assert.strictEqual(RA.trimCharsStart('', 'abc'), 'abc');
+    });
+  });
+
+  context('given an empty string for the target string', function() {
+    specify('should return an empty string', function() {
+      assert.strictEqual(RA.trimCharsStart('-_', ''), '');
+    });
+  });
+
+  it('should curry', function() {
+    assert.strictEqual(RA.trimCharsStart('_-', ''), '');
+    assert.strictEqual(RA.trimCharsStart('_-')(''), '');
+  });
+});
diff --git a/types/test/trimCharsStart.ts b/types/test/trimCharsStart.ts
new file mode 100644
index 0000000000..eae9254fb6
--- /dev/null
+++ b/types/test/trimCharsStart.ts
@@ -0,0 +1,15 @@
+import * as RA from 'ramda-adjunct';
+
+RA.trimCharsStart('-_', '-_-abc-_-'); // $ExpectType string
+RA.trimCharsStart('', '-_-abc-_-'); // $ExpectType string
+RA.trimCharsStart('-_', ''); // $ExpectType string
+
+RA.trimCharsStart(1, 42); // $ExpectError
+RA.trimCharsStart([], 'abc'); // $ExpectError
+RA.trimCharsStart('-_', []); // $ExpectError
+RA.trimCharsStart({}, 'abc'); // $ExpectError
+RA.trimCharsStart('-_', {}); // $ExpectError
+RA.trimCharsStart('-_', null); // $ExpectError
+RA.trimCharsStart(null, 'abc'); // $ExpectError
+RA.trimCharsStart('-_', undefined); // $ExpectError
+RA.trimCharsStart(undefined, 'abc'); // $ExpectError