string-process-comma-separated 2.1.0 → 3.0.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 3.0.3 (2021-11-02)
7
+
8
+ ### Bug Fixes
9
+
10
+ - bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
11
+
12
+ ### Features
13
+
14
+ - migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ - programs now are in ES Modules and won't work with Common JS require()
19
+
20
+ ## 3.0.1 (2021-09-13)
21
+
22
+ ### Bug Fixes
23
+
24
+ - bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
25
+
26
+ ## 3.0.0 (2021-09-09)
27
+
28
+ ### Features
29
+
30
+ - migrate to ES Modules ([8c9d95d](https://github.com/codsen/codsen/commit/8c9d95d5dea0b769c2f070397141918a4893d575))
31
+
32
+ ### BREAKING CHANGES
33
+
34
+ - programs now are in ES Modules and won't work with Common JS require()
35
+
6
36
  ## 2.1.0 (2021-05-24)
7
37
 
8
38
  ### Features
package/README.md CHANGED
@@ -26,10 +26,14 @@
26
26
 
27
27
  ## Install
28
28
 
29
+ This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
30
+
29
31
  ```bash
30
32
  npm i string-process-comma-separated
31
33
  ```
32
34
 
35
+ If you need a legacy version which works with `require`, use version 2.1.0
36
+
33
37
  ## Quick Take
34
38
 
35
39
  ```js
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @name string-process-comma-separated
3
3
  * @fileoverview Extracts chunks from possibly comma or whatever-separated string
4
- * @version 2.1.0
4
+ * @version 3.0.3
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-process-comma-separated/}
8
8
  */
9
9
 
10
- var version$1 = "2.1.0";
10
+ var version$1 = "3.0.3";
11
11
 
12
12
  const version = version$1;
13
13
  function processCommaSep(str, originalOpts) {
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name string-process-comma-separated
3
3
  * @fileoverview Extracts chunks from possibly comma or whatever-separated string
4
- * @version 2.1.0
4
+ * @version 3.0.3
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-process-comma-separated/}
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).stringProcessCommaSeparated={})}(this,(function(e){"use strict";e.processCommaSep=function(e,t){if("string"!=typeof e)throw new Error(`string-process-comma-separated: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}`);if(!e.length||!t||!t.cb&&!t.errCb)return;const r={...{from:0,to:e.length,offset:0,leadingWhitespaceOK:!1,trailingWhitespaceOK:!1,oneSpaceAfterCommaOK:!1,innerWhitespaceAllowed:!1,separator:",",cb:null,errCb:null},...t};Number.isInteger(t.from)||(r.from=0),Number.isInteger(t.to)||(r.to=e.length),Number.isInteger(t.offset)||(r.offset=0);let o=null,s=null,f=!1,a=[],i=null,n=!0;for(let t=r.from;t<r.to;t++){if(e[t].trim()&&e[t]!==r.separator&&(i=t),null!==o||!e[t].trim()||r.separator&&e[t]===r.separator||(f||(f=!0),a.length&&(a.length>1&&a.forEach(((e,t)=>{t&&r.errCb([[e+r.offset,e+1+r.offset]],"Remove separator.",n)})),a=[]),o=t),Number.isInteger(o)&&(t>o&&r.separator&&e[t]===r.separator||t+1===r.to)&&(e.slice(o,t+1===r.to&&e[t]!==r.separator&&e[t].trim()?t+1:t),"function"==typeof r.cb&&r.cb(o+r.offset,(t+1===r.to&&e[t]!==r.separator&&e[t].trim()?t+1:i+1)+r.offset),o=null),e[t].trim()||null!==s||(s=t),null!==s&&(e[t].trim()||t+1===r.to)){if(s===r.from)r.leadingWhitespaceOK||"function"!=typeof r.errCb||r.errCb([[s+r.offset,(t+1===r.to?t+1:t)+r.offset]],"Remove whitespace.",n);else if(e[t].trim()||t+1!==r.to){if(!(r.oneSpaceAfterCommaOK&&e[t].trim()&&t>r.from+1&&" "===e[t-1]&&","===e[t-2]||r.innerWhitespaceAllowed&&f&&e[s-1]&&e[t].trim()&&e[t]!==r.separator&&e[s-1]!==r.separator)){let o=s,a=t;t+1!==r.to||e[t]===r.separator||e[t].trim()||(a+=1);let i="";r.oneSpaceAfterCommaOK&&(" "===e[s]&&e[s-1]===r.separator?o+=1:" "!==e[s]&&(i=" "));let l="Remove whitespace.";!r.innerWhitespaceAllowed&&f&&e[s-1]&&e[t].trim()&&e[t]!==r.separator&&e[s-1]!==r.separator&&(n=!1,l="Bad whitespace."),r.errCb(i.length?[[o+r.offset,a+r.offset,i]]:[[o+r.offset,a+r.offset]],l,n),n=!0}}else r.trailingWhitespaceOK||"function"!=typeof r.errCb||r.errCb([[s+r.offset,t+1+r.offset]],"Remove whitespace.",n);s=null}e[t]===r.separator&&(f?a.push(t):r.errCb([[t+r.offset,t+1+r.offset]],"Remove separator.",n)),t+1===r.to&&a.forEach((e=>{r.errCb([[e+r.offset,e+1+r.offset]],"Remove separator.",n)}))}},e.version="2.1.0",Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).stringProcessCommaSeparated={})}(this,(function(e){"use strict";e.processCommaSep=function(e,t){if("string"!=typeof e)throw new Error(`string-process-comma-separated: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}`);if(!e.length||!t||!t.cb&&!t.errCb)return;const r={...{from:0,to:e.length,offset:0,leadingWhitespaceOK:!1,trailingWhitespaceOK:!1,oneSpaceAfterCommaOK:!1,innerWhitespaceAllowed:!1,separator:",",cb:null,errCb:null},...t};Number.isInteger(t.from)||(r.from=0),Number.isInteger(t.to)||(r.to=e.length),Number.isInteger(t.offset)||(r.offset=0);let o=null,s=null,f=!1,a=[],i=null,n=!0;for(let t=r.from;t<r.to;t++){if(e[t].trim()&&e[t]!==r.separator&&(i=t),null!==o||!e[t].trim()||r.separator&&e[t]===r.separator||(f||(f=!0),a.length&&(a.length>1&&a.forEach(((e,t)=>{t&&r.errCb([[e+r.offset,e+1+r.offset]],"Remove separator.",n)})),a=[]),o=t),Number.isInteger(o)&&(t>o&&r.separator&&e[t]===r.separator||t+1===r.to)&&(e.slice(o,t+1===r.to&&e[t]!==r.separator&&e[t].trim()?t+1:t),"function"==typeof r.cb&&r.cb(o+r.offset,(t+1===r.to&&e[t]!==r.separator&&e[t].trim()?t+1:i+1)+r.offset),o=null),e[t].trim()||null!==s||(s=t),null!==s&&(e[t].trim()||t+1===r.to)){if(s===r.from)r.leadingWhitespaceOK||"function"!=typeof r.errCb||r.errCb([[s+r.offset,(t+1===r.to?t+1:t)+r.offset]],"Remove whitespace.",n);else if(e[t].trim()||t+1!==r.to){if(!(r.oneSpaceAfterCommaOK&&e[t].trim()&&t>r.from+1&&" "===e[t-1]&&","===e[t-2]||r.innerWhitespaceAllowed&&f&&e[s-1]&&e[t].trim()&&e[t]!==r.separator&&e[s-1]!==r.separator)){let o=s,a=t;t+1!==r.to||e[t]===r.separator||e[t].trim()||(a+=1);let i="";r.oneSpaceAfterCommaOK&&(" "===e[s]&&e[s-1]===r.separator?o+=1:" "!==e[s]&&(i=" "));let l="Remove whitespace.";!r.innerWhitespaceAllowed&&f&&e[s-1]&&e[t].trim()&&e[t]!==r.separator&&e[s-1]!==r.separator&&(n=!1,l="Bad whitespace."),r.errCb(i.length?[[o+r.offset,a+r.offset,i]]:[[o+r.offset,a+r.offset]],l,n),n=!0}}else r.trailingWhitespaceOK||"function"!=typeof r.errCb||r.errCb([[s+r.offset,t+1+r.offset]],"Remove whitespace.",n);s=null}e[t]===r.separator&&(f?a.push(t):r.errCb([[t+r.offset,t+1+r.offset]],"Remove separator.",n)),t+1===r.to&&a.forEach((e=>{r.errCb([[e+r.offset,e+1+r.offset]],"Remove separator.",n)}))}},e.version="3.0.3",Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-process-comma-separated",
3
- "version": "2.1.0",
3
+ "version": "3.0.3",
4
4
  "description": "Extracts chunks from possibly comma or whatever-separated string",
5
5
  "keywords": [
6
6
  "characters",
@@ -26,17 +26,21 @@
26
26
  "email": "roy@codsen.com",
27
27
  "url": "https://codsen.com"
28
28
  },
29
- "main": "dist/string-process-comma-separated.cjs.js",
30
- "module": "dist/string-process-comma-separated.esm.js",
31
- "browser": "dist/string-process-comma-separated.umd.js",
29
+ "type": "module",
30
+ "exports": {
31
+ "script": "./dist/string-process-comma-separated.umd.js",
32
+ "default": "./dist/string-process-comma-separated.esm.js"
33
+ },
32
34
  "types": "types/index.d.ts",
33
35
  "scripts": {
34
36
  "build": "rollup -c",
35
- "esbuild": "node '../../scripts/esbuild.js'",
36
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
37
37
  "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
38
+ "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
39
+ "clean_types": "../../scripts/cleanTypes.js",
38
40
  "dev": "rollup -c --dev",
39
41
  "devunittest": "npm run dev && tap --only -R 'base'",
42
+ "esbuild": "node '../../scripts/esbuild.js'",
43
+ "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
40
44
  "format": "npm run lect && npm run prettier && npm run lint",
41
45
  "lect": "lect",
42
46
  "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
@@ -44,22 +48,22 @@
44
48
  "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
45
49
  "republish": "npm publish || :",
46
50
  "tap": "tap",
47
- "tsc": "tsc",
48
51
  "pretest": "npm run build",
49
52
  "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
50
53
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
51
- "unittest": "./node_modules/.bin/tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf",
52
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
53
- "clean_types": "../../scripts/cleanTypes.js"
54
+ "tsc": "tsc",
55
+ "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
54
56
  },
55
57
  "tap": {
58
+ "check-coverage": false,
56
59
  "coverage-report": [
57
60
  "json-summary",
58
61
  "text"
59
62
  ],
60
- "nyc-arg": [
61
- "--exclude=**/*.cjs.js",
62
- "--exclude=**/*.umd.js"
63
+ "node-arg": [
64
+ "--no-warnings",
65
+ "--experimental-loader",
66
+ "@istanbuljs/esm-loader-hook"
63
67
  ],
64
68
  "timeout": 0
65
69
  },
@@ -75,43 +79,47 @@
75
79
  }
76
80
  },
77
81
  "dependencies": {
78
- "@babel/runtime": "^7.14.0"
82
+ "@babel/runtime": "^7.16.0"
79
83
  },
80
84
  "devDependencies": {
81
- "@babel/cli": "^7.14.3",
82
- "@babel/core": "^7.14.3",
83
- "@babel/node": "^7.14.2",
84
- "@babel/plugin-external-helpers": "^7.12.13",
85
- "@babel/plugin-proposal-class-properties": "^7.13.0",
86
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2",
87
- "@babel/plugin-proposal-object-rest-spread": "^7.14.2",
88
- "@babel/plugin-proposal-optional-chaining": "^7.14.2",
89
- "@babel/plugin-transform-runtime": "^7.14.3",
90
- "@babel/preset-env": "^7.14.2",
91
- "@babel/preset-typescript": "^7.13.0",
92
- "@babel/register": "^7.13.16",
85
+ "@babel/cli": "^7.16.0",
86
+ "@babel/core": "^7.16.0",
87
+ "@babel/node": "^7.16.0",
88
+ "@babel/plugin-external-helpers": "^7.16.0",
89
+ "@babel/plugin-proposal-class-properties": "^7.16.0",
90
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
91
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
92
+ "@babel/plugin-proposal-optional-chaining": "^7.16.0",
93
+ "@babel/plugin-transform-runtime": "^7.16.0",
94
+ "@babel/preset-env": "^7.16.0",
95
+ "@babel/preset-typescript": "^7.16.0",
96
+ "@babel/register": "^7.16.0",
97
+ "@istanbuljs/esm-loader-hook": "^0.1.2",
93
98
  "@rollup/plugin-babel": "^5.3.0",
94
- "@rollup/plugin-commonjs": "^19.0.0",
99
+ "@rollup/plugin-commonjs": "^21.0.1",
95
100
  "@rollup/plugin-json": "^4.1.0",
96
- "@rollup/plugin-node-resolve": "^13.0.0",
97
- "@rollup/plugin-strip": "^2.0.1",
98
- "@rollup/plugin-typescript": "^8.2.1",
99
- "@types/node": "^15.6.0",
100
- "@types/tap": "^15.0.1",
101
- "@typescript-eslint/eslint-plugin": "^4.24.0",
102
- "@typescript-eslint/parser": "^4.24.0",
103
- "core-js": "^3.12.1",
101
+ "@rollup/plugin-node-resolve": "^13.0.6",
102
+ "@rollup/plugin-strip": "^2.1.0",
103
+ "@rollup/plugin-typescript": "^8.3.0",
104
+ "@types/node": "^16.11.6",
105
+ "@types/tap": "^15.0.5",
106
+ "@typescript-eslint/eslint-plugin": "^5.2.0",
107
+ "@typescript-eslint/parser": "^5.2.0",
108
+ "core-js": "^3.19.0",
104
109
  "cross-env": "^7.0.3",
105
- "eslint": "^7.27.0",
106
- "lect": "^0.17.0",
107
- "rollup": "^2.49.0",
110
+ "eslint": "^8.1.0",
111
+ "lect": "^0.18.3",
112
+ "rollup": "^2.59.0",
108
113
  "rollup-plugin-ascii": "^0.0.3",
109
114
  "rollup-plugin-banner": "^0.2.1",
110
115
  "rollup-plugin-cleanup": "^3.2.1",
111
- "rollup-plugin-dts": "^3.0.1",
116
+ "rollup-plugin-dts": "^4.0.0",
112
117
  "rollup-plugin-terser": "^7.0.2",
113
- "tap": "^14.11.0",
114
- "tslib": "^2.2.0",
115
- "typescript": "^4.2.4"
118
+ "tap": "^15.0.10",
119
+ "tslib": "^2.3.1",
120
+ "typescript": "^4.4.4"
121
+ },
122
+ "engines": {
123
+ "node": ">=12"
116
124
  }
117
125
  }
@@ -1,142 +0,0 @@
1
- /**
2
- * @name string-process-comma-separated
3
- * @fileoverview Extracts chunks from possibly comma or whatever-separated string
4
- * @version 2.1.0
5
- * @author Roy Revelt, Codsen Ltd
6
- * @license MIT
7
- * {@link https://codsen.com/os/string-process-comma-separated/}
8
- */
9
-
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, '__esModule', { value: true });
13
-
14
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
15
- var _typeof = require('@babel/runtime/helpers/typeof');
16
-
17
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
-
19
- var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
20
- var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
21
-
22
- var version$1 = "2.1.0";
23
-
24
- var version = version$1;
25
- function processCommaSep(str, originalOpts) {
26
- if (typeof str !== "string") {
27
- throw new Error("string-process-comma-separated: [THROW_ID_01] input must be string! It was given as ".concat(_typeof__default['default'](str), ", equal to:\n").concat(JSON.stringify(str, null, 4)));
28
- } else if (!str.length || !originalOpts || !originalOpts.cb && !originalOpts.errCb) {
29
- return;
30
- }
31
- var defaults = {
32
- from: 0,
33
- to: str.length,
34
- offset: 0,
35
- leadingWhitespaceOK: false,
36
- trailingWhitespaceOK: false,
37
- oneSpaceAfterCommaOK: false,
38
- innerWhitespaceAllowed: false,
39
- separator: ",",
40
- cb: null,
41
- errCb: null
42
- };
43
- var opts = _objectSpread__default['default'](_objectSpread__default['default']({}, defaults), originalOpts);
44
- if (!Number.isInteger(originalOpts.from)) {
45
- opts.from = 0;
46
- }
47
- if (!Number.isInteger(originalOpts.to)) {
48
- opts.to = str.length;
49
- }
50
- if (!Number.isInteger(originalOpts.offset)) {
51
- opts.offset = 0;
52
- }
53
- var chunkStartsAt = null;
54
- var whitespaceStartsAt = null;
55
- var firstNonwhitespaceNonseparatorCharFound = false;
56
- var separatorsArr = [];
57
- var lastNonWhitespaceCharAt = null;
58
- var fixable = true;
59
- for (var i = opts.from; i < opts.to; i++) {
60
- if (str[i].trim() && str[i] !== opts.separator) {
61
- lastNonWhitespaceCharAt = i;
62
- }
63
- if (chunkStartsAt === null && str[i].trim() && (!opts.separator || str[i] !== opts.separator)) {
64
- if (!firstNonwhitespaceNonseparatorCharFound) {
65
- firstNonwhitespaceNonseparatorCharFound = true;
66
- }
67
- if (separatorsArr.length) {
68
- if (separatorsArr.length > 1) {
69
- separatorsArr.forEach(function (separatorsIdx, orderNumber) {
70
- if (orderNumber) {
71
- opts.errCb([[separatorsIdx + opts.offset, separatorsIdx + 1 + opts.offset]], "Remove separator.", fixable);
72
- }
73
- });
74
- }
75
- separatorsArr = [];
76
- }
77
- chunkStartsAt = i;
78
- }
79
- if (Number.isInteger(chunkStartsAt) && (i > chunkStartsAt && opts.separator && str[i] === opts.separator || i + 1 === opts.to)) {
80
- str.slice(chunkStartsAt, i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() ? i + 1 : i);
81
- if (typeof opts.cb === "function") {
82
- opts.cb(chunkStartsAt + opts.offset, (i + 1 === opts.to && str[i] !== opts.separator && str[i].trim() ? i + 1 : lastNonWhitespaceCharAt + 1) + opts.offset);
83
- }
84
- chunkStartsAt = null;
85
- }
86
- if (!str[i].trim() && whitespaceStartsAt === null) {
87
- whitespaceStartsAt = i;
88
- }
89
- if (whitespaceStartsAt !== null && (str[i].trim() || i + 1 === opts.to)) {
90
- if (whitespaceStartsAt === opts.from) {
91
- if (!opts.leadingWhitespaceOK && typeof opts.errCb === "function") {
92
- opts.errCb([[whitespaceStartsAt + opts.offset, (i + 1 === opts.to ? i + 1 : i) + opts.offset]], "Remove whitespace.", fixable);
93
- }
94
- } else if (!str[i].trim() && i + 1 === opts.to) {
95
- if (!opts.trailingWhitespaceOK && typeof opts.errCb === "function") {
96
- opts.errCb([[whitespaceStartsAt + opts.offset, i + 1 + opts.offset]], "Remove whitespace.", fixable);
97
- }
98
- } else if ((!opts.oneSpaceAfterCommaOK || !(str[i].trim() && i > opts.from + 1 && str[i - 1] === " " && str[i - 2] === ",")) && (!opts.innerWhitespaceAllowed || !(firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim() && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator))) {
99
- var startingIdx = whitespaceStartsAt;
100
- var endingIdx = i;
101
- if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim()) {
102
- endingIdx += 1;
103
- }
104
- var whatToAdd = "";
105
- if (opts.oneSpaceAfterCommaOK) {
106
- if (str[whitespaceStartsAt] === " " && str[whitespaceStartsAt - 1] === opts.separator) {
107
- startingIdx += 1;
108
- } else if (str[whitespaceStartsAt] !== " ") {
109
- whatToAdd = " ";
110
- }
111
- }
112
- var message = "Remove whitespace.";
113
- if (!opts.innerWhitespaceAllowed && firstNonwhitespaceNonseparatorCharFound && str[whitespaceStartsAt - 1] && str[i].trim() && str[i] !== opts.separator && str[whitespaceStartsAt - 1] !== opts.separator) {
114
- fixable = false;
115
- message = "Bad whitespace.";
116
- }
117
- if (whatToAdd.length) {
118
- opts.errCb([[startingIdx + opts.offset, endingIdx + opts.offset, whatToAdd]], message, fixable);
119
- } else {
120
- opts.errCb([[startingIdx + opts.offset, endingIdx + opts.offset]], message, fixable);
121
- }
122
- fixable = true;
123
- }
124
- whitespaceStartsAt = null;
125
- }
126
- if (str[i] === opts.separator) {
127
- if (!firstNonwhitespaceNonseparatorCharFound) {
128
- opts.errCb([[i + opts.offset, i + 1 + opts.offset]], "Remove separator.", fixable);
129
- } else {
130
- separatorsArr.push(i);
131
- }
132
- }
133
- if (i + 1 === opts.to) {
134
- separatorsArr.forEach(function (separatorsIdx) {
135
- opts.errCb([[separatorsIdx + opts.offset, separatorsIdx + 1 + opts.offset]], "Remove separator.", fixable);
136
- });
137
- }
138
- }
139
- }
140
-
141
- exports.processCommaSep = processCommaSep;
142
- exports.version = version;
@@ -1,241 +0,0 @@
1
- /**
2
- * @name string-process-comma-separated
3
- * @fileoverview Extracts chunks from possibly comma or whatever-separated string
4
- * @version 2.1.0
5
- * @author Roy Revelt, Codsen Ltd
6
- * @license MIT
7
- * {@link https://codsen.com/os/string-process-comma-separated/}
8
- */
9
-
10
- (function (global, factory) {
11
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
12
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
13
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.stringProcessCommaSeparated = {}));
14
- }(this, (function (exports) { 'use strict';
15
-
16
- var version$1 = "2.1.0";
17
-
18
- const version = version$1;
19
- function processCommaSep(str, originalOpts) {
20
- // insurance:
21
- if (typeof str !== "string") {
22
- throw new Error(`string-process-comma-separated: [THROW_ID_01] input must be string! It was given as ${typeof str}, equal to:\n${JSON.stringify(str, null, 4)}`);
23
- }
24
- else if (!str.length ||
25
- !originalOpts ||
26
- (!originalOpts.cb && !originalOpts.errCb)) {
27
- // if input str is empty or there are no callbacks, exit early
28
- return;
29
- }
30
- // opts preparation:
31
- const defaults = {
32
- from: 0,
33
- to: str.length,
34
- offset: 0,
35
- leadingWhitespaceOK: false,
36
- trailingWhitespaceOK: false,
37
- oneSpaceAfterCommaOK: false,
38
- innerWhitespaceAllowed: false,
39
- separator: ",",
40
- cb: null,
41
- errCb: null,
42
- };
43
- const opts = { ...defaults, ...originalOpts };
44
- // patch from/to values, they might have been given as nulls etc.
45
- if (!Number.isInteger(originalOpts.from)) {
46
- opts.from = 0;
47
- }
48
- if (!Number.isInteger(originalOpts.to)) {
49
- opts.to = str.length;
50
- }
51
- if (!Number.isInteger(originalOpts.offset)) {
52
- opts.offset = 0;
53
- }
54
- // action:
55
- let chunkStartsAt = null;
56
- let whitespaceStartsAt = null;
57
- let firstNonwhitespaceNonseparatorCharFound = false;
58
- let separatorsArr = []; // needed to catch trailing separators
59
- let lastNonWhitespaceCharAt = null;
60
- let fixable = true;
61
- for (let i = opts.from; i < opts.to; i++) {
62
- // catch the last nonwhitespace char
63
- if (str[i].trim() && str[i] !== opts.separator) {
64
- lastNonWhitespaceCharAt = i;
65
- }
66
- // catch the beginning of a chunk
67
- if (chunkStartsAt === null &&
68
- str[i].trim() &&
69
- (!opts.separator || str[i] !== opts.separator)) {
70
- if (!firstNonwhitespaceNonseparatorCharFound) {
71
- firstNonwhitespaceNonseparatorCharFound = true;
72
- }
73
- // if there was only one separator up to now, wipe it
74
- if (separatorsArr.length) {
75
- if (separatorsArr.length > 1) {
76
- // eslint-disable-next-line no-loop-func
77
- separatorsArr.forEach((separatorsIdx, orderNumber) => {
78
- if (orderNumber) {
79
- opts.errCb([
80
- [
81
- separatorsIdx + opts.offset,
82
- separatorsIdx + 1 + opts.offset,
83
- ],
84
- ], "Remove separator.", fixable);
85
- }
86
- });
87
- }
88
- separatorsArr = [];
89
- }
90
- chunkStartsAt = i;
91
- }
92
- // catch the ending of a chunk
93
- if (Number.isInteger(chunkStartsAt) &&
94
- ((i > chunkStartsAt &&
95
- opts.separator &&
96
- str[i] === opts.separator) ||
97
- i + 1 === opts.to)) {
98
- str.slice(chunkStartsAt, i + 1 === opts.to && str[i] !== opts.separator && str[i].trim()
99
- ? i + 1
100
- : i);
101
- // ping the cb
102
- if (typeof opts.cb === "function") {
103
- opts.cb(chunkStartsAt + opts.offset, (i + 1 === opts.to && str[i] !== opts.separator && str[i].trim()
104
- ? i + 1
105
- : lastNonWhitespaceCharAt + 1) + opts.offset);
106
- }
107
- // reset
108
- chunkStartsAt = null;
109
- }
110
- // catch the beginning of a whitespace
111
- if (!str[i].trim() && whitespaceStartsAt === null) {
112
- whitespaceStartsAt = i;
113
- }
114
- // catch the ending of a whitespace
115
- if (whitespaceStartsAt !== null && (str[i].trim() || i + 1 === opts.to)) {
116
- if (whitespaceStartsAt === opts.from) {
117
- if (!opts.leadingWhitespaceOK && typeof opts.errCb === "function") {
118
- opts.errCb([
119
- [
120
- whitespaceStartsAt + opts.offset,
121
- (i + 1 === opts.to ? i + 1 : i) + opts.offset,
122
- ],
123
- ], "Remove whitespace.", fixable);
124
- }
125
- // else - fine
126
- }
127
- else if (!str[i].trim() && i + 1 === opts.to) {
128
- // if it's trailing whitespace, we're on the last character
129
- // (right before opts.to)
130
- if (!opts.trailingWhitespaceOK && typeof opts.errCb === "function") {
131
- opts.errCb([[whitespaceStartsAt + opts.offset, i + 1 + opts.offset]], "Remove whitespace.", fixable);
132
- }
133
- // else - fine
134
- }
135
- else if ((!opts.oneSpaceAfterCommaOK ||
136
- !(str[i].trim() &&
137
- i > opts.from + 1 &&
138
- str[i - 1] === " " &&
139
- str[i - 2] === ",")) &&
140
- (!opts.innerWhitespaceAllowed ||
141
- !(firstNonwhitespaceNonseparatorCharFound &&
142
- str[whitespaceStartsAt - 1] &&
143
- str[i].trim() &&
144
- str[i] !== opts.separator &&
145
- str[whitespaceStartsAt - 1] !== opts.separator))) {
146
- // exclude single space after a comma, with condition that something
147
- // non-whitespacey follows
148
- // maybe opts.oneSpaceAfterCommaOK is on?
149
- let startingIdx = whitespaceStartsAt;
150
- let endingIdx = i;
151
- if (i + 1 === opts.to && str[i] !== opts.separator && !str[i].trim()) {
152
- endingIdx += 1;
153
- }
154
- // i + 1 === opts.to && str[i] !== opts.separator && str[i].trim()
155
- // ? i + 1
156
- // : i;
157
- let whatToAdd = "";
158
- if (opts.oneSpaceAfterCommaOK) {
159
- if (str[whitespaceStartsAt] === " " &&
160
- str[whitespaceStartsAt - 1] === opts.separator) {
161
- // if first whitespace chunk's character is a space, leave it
162
- startingIdx += 1;
163
- }
164
- else if (str[whitespaceStartsAt] !== " ") {
165
- // if first whitespace chunk's character is not a space,
166
- // replace whole chunk with a space
167
- whatToAdd = " ";
168
- }
169
- }
170
- let message = "Remove whitespace.";
171
- // What if there's a space in the middle of a value, for example, URL?
172
- // <input accept="abc,def ghi,jkl">
173
- // ^
174
- // here.
175
- // We identify it by checking, is there a separator in front.
176
- if (!opts.innerWhitespaceAllowed &&
177
- firstNonwhitespaceNonseparatorCharFound &&
178
- str[whitespaceStartsAt - 1] &&
179
- str[i].trim() &&
180
- str[i] !== opts.separator &&
181
- str[whitespaceStartsAt - 1] !== opts.separator) {
182
- fixable = false;
183
- message = "Bad whitespace.";
184
- }
185
- if (whatToAdd.length) {
186
- opts.errCb([[startingIdx + opts.offset, endingIdx + opts.offset, whatToAdd]], message, fixable);
187
- }
188
- else {
189
- opts.errCb([[startingIdx + opts.offset, endingIdx + opts.offset]], message, fixable);
190
- }
191
- // reset fixable
192
- fixable = true;
193
- }
194
- // reset
195
- whitespaceStartsAt = null;
196
- }
197
- // catch the separator
198
- if (str[i] === opts.separator) {
199
- if (!firstNonwhitespaceNonseparatorCharFound) {
200
- opts.errCb([[i + opts.offset, i + 1 + opts.offset]], "Remove separator.", fixable);
201
- }
202
- else {
203
- separatorsArr.push(i);
204
- }
205
- }
206
- // |
207
- // |
208
- // |
209
- // |
210
- // |
211
- // |
212
- // |
213
- // |
214
- // |
215
- // BOTTOM RULES
216
- // |
217
- // |
218
- // |
219
- // |
220
- // |
221
- // |
222
- // |
223
- // |
224
- // |
225
- // catch the end of the string
226
- if (i + 1 === opts.to) {
227
- // eslint-disable-next-line no-loop-func
228
- separatorsArr.forEach((separatorsIdx) => {
229
- opts.errCb([[separatorsIdx + opts.offset, separatorsIdx + 1 + opts.offset]], "Remove separator.", fixable);
230
- });
231
- }
232
- // logging
233
- }
234
- }
235
-
236
- exports.processCommaSep = processCommaSep;
237
- exports.version = version;
238
-
239
- Object.defineProperty(exports, '__esModule', { value: true });
240
-
241
- })));