@nyaomaru/divider 1.0.21 → 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
 
@@ -90,6 +90,34 @@ const flatArray = divider(['hello', 'new world'], ' ', 2, { flatten: true });
90
90
  // ['he', 'llo', 'ne', 'w', 'wor', 'ld']
91
91
  ```
92
92
 
93
+ ### 📌 `dividerFirst()` Usage
94
+
95
+ `dividerFirst()` returns only the first divided element from the result.
96
+
97
+ ```ts
98
+ import { dividerFirst } from '@nyaomaru/divider';
99
+
100
+ const firstElement = dividerFirst('hello world', ' ');
101
+ // 'hello'
102
+
103
+ const firstArrayElement = dividerFirst(['hello', 'world'], 2);
104
+ // 'he'
105
+ ```
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
+
93
121
  ## 🎯 Options
94
122
 
95
123
  | Option | Type | Default | Description |
@@ -113,6 +141,8 @@ const result2 = divider(words, 2, { flatten: true });
113
141
  - Works with both `strings` and `arrays of strings`
114
142
  - Supports `multiple separators` (mixing indexes and characters).
115
143
  - Provides an `optional flattening` feature for array results.
144
+ - **Get only the first divided element using `dividerFirst()`**
145
+ - **Get only the last divided element using `dividerLast()`**
116
146
 
117
147
  ## 🛠 Contributing
118
148
 
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dividerFirst = dividerFirst;
4
+ const divider_1 = require("@/core/divider");
5
+ function dividerFirst(input, ...args) {
6
+ var _a, _b;
7
+ const result = (0, divider_1.divider)(input, ...args);
8
+ if (Array.isArray(result[0])) {
9
+ return (_a = result[0][0]) !== null && _a !== void 0 ? _a : '';
10
+ }
11
+ return (_b = result[0]) !== null && _b !== void 0 ? _b : '';
12
+ }
@@ -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,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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
+ var divider_first_1 = require("@/core/divider-first");
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 dividerFirst(input, ...args) {
3
+ var _a, _b;
4
+ const result = divider(input, ...args);
5
+ if (Array.isArray(result[0])) {
6
+ return (_a = result[0][0]) !== null && _a !== void 0 ? _a : '';
7
+ }
8
+ return (_b = result[0]) !== null && _b !== void 0 ? _b : '';
9
+ }
@@ -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 +1,3 @@
1
1
  export { divider } from '@/core/divider';
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 dividerFirst<T extends string | string[], F extends boolean = false>(input: T, ...args: DividerArgs<F>): string;
@@ -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,2 +1,4 @@
1
1
  export { divider } from '@/core/divider';
2
+ export { dividerFirst } from '@/core/divider-first';
3
+ export { dividerLast } from '@/core/divider-last';
2
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.0.21",
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",