@nyaomaru/divider 1.1.0 → 1.2.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/README.md CHANGED
@@ -43,7 +43,7 @@ yarn add @nyaomaru/divider
43
43
 
44
44
  👉 [Check out the full documentation here!](https://divider-docs.vercel.app/)
45
45
 
46
- `divider` allows you to split a string or an array of strings using index positions or delimiters.
46
+ `divider` allows you to divide a string or an array of strings using index positions or delimiters.
47
47
 
48
48
  ### 📌 Basic Usage
49
49
 
@@ -104,6 +104,20 @@ const firstArrayElement = dividerFirst(['hello', 'world'], 2);
104
104
  // 'he'
105
105
  ```
106
106
 
107
+ ### 📌 `dividerLast()` Usage
108
+
109
+ `dividerLast()` returns only the last divided element from the result.
110
+
111
+ ```ts
112
+ import { dividerLast } from '@nyaomaru/divider';
113
+
114
+ const firstElement = dividerLast('hello world', ' ');
115
+ // 'world'
116
+
117
+ const firstArrayElement = dividerLast(['hello', 'world'], 2);
118
+ // 'rld'
119
+ ```
120
+
107
121
  ## 🎯 Options
108
122
 
109
123
  | Option | Type | Default | Description |
@@ -128,6 +142,7 @@ const result2 = divider(words, 2, { flatten: true });
128
142
  - Supports `multiple separators` (mixing indexes and characters).
129
143
  - Provides an `optional flattening` feature for array results.
130
144
  - **Get only the first divided element using `dividerFirst()`**
145
+ - **Get only the last divided element using `dividerLast()`**
131
146
 
132
147
  ## 🛠 Contributing
133
148
 
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dividerLast = dividerLast;
4
+ const divider_1 = require("@/core/divider");
5
+ function dividerLast(input, ...args) {
6
+ var _a;
7
+ const result = (0, divider_1.divider)(input, ...args);
8
+ if (result.length === 0)
9
+ return '';
10
+ const lastElement = result[result.length - 1];
11
+ return Array.isArray(lastElement) ? ((_a = lastElement.at(-1)) !== null && _a !== void 0 ? _a : '') : lastElement;
12
+ }
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dividerFirst = exports.divider = void 0;
3
+ exports.dividerLast = exports.dividerFirst = exports.divider = void 0;
4
4
  var divider_1 = require("@/core/divider");
5
5
  Object.defineProperty(exports, "divider", { enumerable: true, get: function () { return divider_1.divider; } });
6
6
  var divider_first_1 = require("@/core/divider-first");
7
7
  Object.defineProperty(exports, "dividerFirst", { enumerable: true, get: function () { return divider_first_1.dividerFirst; } });
8
+ var divider_last_1 = require("@/core/divider-last");
9
+ Object.defineProperty(exports, "dividerLast", { enumerable: true, get: function () { return divider_last_1.dividerLast; } });
@@ -0,0 +1,9 @@
1
+ import { divider } from '@/core/divider';
2
+ export function dividerLast(input, ...args) {
3
+ var _a;
4
+ const result = divider(input, ...args);
5
+ if (result.length === 0)
6
+ return '';
7
+ const lastElement = result[result.length - 1];
8
+ return Array.isArray(lastElement) ? ((_a = lastElement.at(-1)) !== null && _a !== void 0 ? _a : '') : lastElement;
9
+ }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { divider } from '@/core/divider';
2
2
  export { dividerFirst } from '@/core/divider-first';
3
+ export { dividerLast } from '@/core/divider-last';
@@ -0,0 +1,2 @@
1
+ import type { DividerArgs } from '@/core/types';
2
+ export declare function dividerLast<T extends string | string[], F extends boolean>(input: T, ...args: DividerArgs<F>): string;
@@ -1,3 +1,4 @@
1
1
  export { divider } from '@/core/divider';
2
2
  export { dividerFirst } from '@/core/divider-first';
3
+ export { dividerLast } from '@/core/divider-last';
3
4
  export type { DividerResult } from '@/core/types';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/esm/index.js",