@nyaomaru/divider 2.0.18 → 2.0.19

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/index.cjs CHANGED
@@ -326,19 +326,19 @@ function trimSegments(segments, preserveEmpty) {
326
326
  }
327
327
 
328
328
  // src/utils/option-transformers.ts
329
- function applyTrimOption(output, options, shouldPreserveEmpty) {
329
+ function applyTrimOption(output, options) {
330
330
  if (!options.trim) return output;
331
331
  return mapDividerOutput(
332
332
  output,
333
- (segments) => trimSegments(segments, shouldPreserveEmpty)
333
+ (segments) => trimSegments(segments, options.preserveEmpty)
334
334
  );
335
335
  }
336
336
  function applyFlattenOption(output, options) {
337
337
  return options.flatten && isNestedStringArray(output) ? output.flat() : output;
338
338
  }
339
- function applyExcludeOption(output, options, shouldPreserveEmpty) {
339
+ function applyExcludeOption(output, options) {
340
340
  const shouldKeep = resolveExcludePredicate(options.exclude);
341
- return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, shouldPreserveEmpty);
341
+ return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, options.preserveEmpty);
342
342
  }
343
343
 
344
344
  // src/utils/option-arguments.ts
@@ -354,12 +354,28 @@ function extractOptions(args) {
354
354
  }
355
355
 
356
356
  // src/utils/option.ts
357
+ var DEFAULT_RESOLVED_OPTIONS = {
358
+ flatten: false,
359
+ trim: false,
360
+ preserveEmpty: false,
361
+ exclude: DIVIDER_EXCLUDE_MODES.NONE
362
+ };
363
+ var isDividerExcludeMode = (value) => isString(value) && Object.values(DIVIDER_EXCLUDE_MODES).includes(
364
+ value
365
+ );
366
+ var resolveExcludeMode = (value) => isDividerExcludeMode(value) ? value : DEFAULT_RESOLVED_OPTIONS.exclude;
367
+ var resolveDividerOptions = (options) => ({
368
+ flatten: options.flatten === true,
369
+ trim: options.trim === true,
370
+ preserveEmpty: options.preserveEmpty === true,
371
+ exclude: resolveExcludeMode(options.exclude)
372
+ });
357
373
  function applyDividerOptions(result, options) {
358
- const shouldPreserveEmpty = options.preserveEmpty === true;
374
+ const resolvedOptions = resolveDividerOptions(options);
359
375
  let output = result;
360
- output = applyTrimOption(output, options, shouldPreserveEmpty);
361
- output = applyFlattenOption(output, options);
362
- output = applyExcludeOption(output, options, shouldPreserveEmpty);
376
+ output = applyTrimOption(output, resolvedOptions);
377
+ output = applyFlattenOption(output, resolvedOptions);
378
+ output = applyExcludeOption(output, resolvedOptions);
363
379
  return output;
364
380
  }
365
381
 
package/dist/index.js CHANGED
@@ -292,19 +292,19 @@ function trimSegments(segments, preserveEmpty) {
292
292
  }
293
293
 
294
294
  // src/utils/option-transformers.ts
295
- function applyTrimOption(output, options, shouldPreserveEmpty) {
295
+ function applyTrimOption(output, options) {
296
296
  if (!options.trim) return output;
297
297
  return mapDividerOutput(
298
298
  output,
299
- (segments) => trimSegments(segments, shouldPreserveEmpty)
299
+ (segments) => trimSegments(segments, options.preserveEmpty)
300
300
  );
301
301
  }
302
302
  function applyFlattenOption(output, options) {
303
303
  return options.flatten && isNestedStringArray(output) ? output.flat() : output;
304
304
  }
305
- function applyExcludeOption(output, options, shouldPreserveEmpty) {
305
+ function applyExcludeOption(output, options) {
306
306
  const shouldKeep = resolveExcludePredicate(options.exclude);
307
- return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, shouldPreserveEmpty);
307
+ return shouldKeep == null ? output : filterDividerOutput(output, shouldKeep, options.preserveEmpty);
308
308
  }
309
309
 
310
310
  // src/utils/option-arguments.ts
@@ -320,12 +320,28 @@ function extractOptions(args) {
320
320
  }
321
321
 
322
322
  // src/utils/option.ts
323
+ var DEFAULT_RESOLVED_OPTIONS = {
324
+ flatten: false,
325
+ trim: false,
326
+ preserveEmpty: false,
327
+ exclude: DIVIDER_EXCLUDE_MODES.NONE
328
+ };
329
+ var isDividerExcludeMode = (value) => isString(value) && Object.values(DIVIDER_EXCLUDE_MODES).includes(
330
+ value
331
+ );
332
+ var resolveExcludeMode = (value) => isDividerExcludeMode(value) ? value : DEFAULT_RESOLVED_OPTIONS.exclude;
333
+ var resolveDividerOptions = (options) => ({
334
+ flatten: options.flatten === true,
335
+ trim: options.trim === true,
336
+ preserveEmpty: options.preserveEmpty === true,
337
+ exclude: resolveExcludeMode(options.exclude)
338
+ });
323
339
  function applyDividerOptions(result, options) {
324
- const shouldPreserveEmpty = options.preserveEmpty === true;
340
+ const resolvedOptions = resolveDividerOptions(options);
325
341
  let output = result;
326
- output = applyTrimOption(output, options, shouldPreserveEmpty);
327
- output = applyFlattenOption(output, options);
328
- output = applyExcludeOption(output, options, shouldPreserveEmpty);
342
+ output = applyTrimOption(output, resolvedOptions);
343
+ output = applyFlattenOption(output, resolvedOptions);
344
+ output = applyExcludeOption(output, resolvedOptions);
329
345
  return output;
330
346
  }
331
347
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "2.0.18",
4
+ "version": "2.0.19",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",