ac-sanitizer 4.2.1 → 5.0.1

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
@@ -1,4 +1,34 @@
1
1
 
2
+ ## [5.0.1](https://github.com/mmpro/ac-sanitizer/compare/v5.0.0..v5.0.1) (2025-08-31 12:35:43)
3
+
4
+
5
+ ### Bug Fix
6
+
7
+ * **App:** Add option unique for arrays | MP | [2484bd72c6ca31610361056eb05dd6b0b05bf3c3](https://github.com/mmpro/ac-sanitizer/commit/2484bd72c6ca31610361056eb05dd6b0b05bf3c3)
8
+ If unique is true, duplicates will be removed from array
9
+ Related issues:
10
+ ### Chores
11
+
12
+ * **App:** Updated packages | MP | [f4689d9b3bdbde42098fef0827cad691dd5d651f](https://github.com/mmpro/ac-sanitizer/commit/f4689d9b3bdbde42098fef0827cad691dd5d651f)
13
+ Updated packages
14
+ Related issues:
15
+
16
+ # [5.0.0](https://github.com/mmpro/ac-sanitizer/compare/v4.2.1..v5.0.0) (2025-05-21 15:57:54)
17
+
18
+
19
+ ### Bug Fix
20
+
21
+ * **App:** Do not require minLength of 2 chars for strings | MP | [ff2c0d4c453725cfe3f6ecd84ca5160bd907b9b1](https://github.com/mmpro/ac-sanitizer/commit/ff2c0d4c453725cfe3f6ecd84ca5160bd907b9b1)
22
+ If you want to set minLength, you can still do so, but default for string is 0 = no minLength
23
+ Related issues:
24
+ ### Tests
25
+
26
+ * **App:** Fixed test | MP | [0d335b956b012023bbe6f3214d2d961ff8baa04a](https://github.com/mmpro/ac-sanitizer/commit/0d335b956b012023bbe6f3214d2d961ff8baa04a)
27
+ Fixed test
28
+ Related issues:
29
+ ## BREAKING CHANGES
30
+ * **App:** MinLength of 2 chars for strings is no longer hardcoded/required
31
+
2
32
  ## [4.2.1](https://github.com/mmpro/ac-sanitizer/compare/v4.2.0..v4.2.1) (2025-05-19 06:12:14)
3
33
 
4
34
 
package/README.md CHANGED
@@ -87,6 +87,7 @@ iso-639 | { iso-639-2: 'tlh', translations: [] } -> tlh (with convert=iso-639-2)
87
87
  Type | Options | Remarks
88
88
  --- | --- | --- |
89
89
  any | | Any can be string, integer, boolean, object or array - it will be automatically detected.
90
+ array | unique | If unique=true, duplicate entries will be removed from array
90
91
  base64 | | Checks if a string is base64 encoded, optional with field option "convert" (to string)
91
92
  boolean | |
92
93
  cidr | | Check CIDR, see example
package/index.js CHANGED
@@ -69,7 +69,7 @@ const sanitizer = function() {
69
69
  _.some(fields, (field) => {
70
70
  // FIELD definitions
71
71
  let fieldName = field.field
72
- let minLength = _.isNumber(field.minLength) ? field.minLength : 2
72
+ let minLength = _.isNumber(field.minLength) ? field.minLength : 0
73
73
  let allowedValues = _.get(field, 'enum', _.get(field, 'isMemberOf.group'))
74
74
  if (_.isString(allowedValues)) {
75
75
  // placeholder for enum:
@@ -300,6 +300,8 @@ const sanitizer = function() {
300
300
  if (!error && _.isFunction(_.get(schema, 'verify'))) {
301
301
  error = schema.verify(value)
302
302
  }
303
+
304
+ if (field.unique) _.set(paramsToCheck, fieldName, _.uniqWith(value, _.isEqual))
303
305
  }
304
306
  else if (field.type === 'object') {
305
307
  if (!_.isPlainObject(value)) error = { message: fieldName + '_' + getTypeMapping(field.type, 'errorMessage') }
package/package.json CHANGED
@@ -4,23 +4,23 @@
4
4
  "author": "Mark Poepping (https://www.admiralcloud.com)",
5
5
  "license": "MIT",
6
6
  "repository": "admiralcloud/ac-sanitizer",
7
- "version": "4.2.1",
7
+ "version": "5.0.1",
8
8
  "homepage": "https://www.admiralcloud.com",
9
9
  "dependencies": {
10
- "ac-countrylist": "^1.0.13",
11
- "ac-file-extensions": "^2.0.10",
12
- "ac-ip": "^4.1.3",
10
+ "ac-countrylist": "^1.0.14",
11
+ "ac-file-extensions": "^2.0.11",
12
+ "ac-ip": "^4.1.4",
13
13
  "chai": "^4.5.0",
14
14
  "date-and-time": "^3.6.0",
15
15
  "hashids": "^2.3.0",
16
16
  "lodash": "^4.17.21",
17
- "validator": "^13.15.0"
17
+ "validator": "^13.15.15"
18
18
  },
19
19
  "devDependencies": {
20
- "ac-semantic-release": "^0.4.6",
20
+ "ac-semantic-release": "^0.4.7",
21
21
  "c8": "^10.1.3",
22
- "eslint": "^9.27.0",
23
- "mocha": "^11.3.0"
22
+ "eslint": "^9.34.0",
23
+ "mocha": "^11.7.1"
24
24
  },
25
25
  "scripts": {
26
26
  "test": "mocha --reporter spec --bail",
@@ -41,6 +41,8 @@ module.exports = {
41
41
  { name: 'Array of strings with enum - uppercase vs lowercase - with ignoreCase', type: 'array', valueType: 'string', ignoreCase: true, value: ['ABC', 'DEF'], enum: ['abc'], error: 'array_atLeastOneValueFailed' },
42
42
  { name: 'Array of urls with https', type: 'array', valueType: 'url', value: ['https://www.admiralcloud.com'], expected: ['https://www.admiralcloud.com'] },
43
43
  { name: 'Array of urls with http and https - only https is allowed', type: 'array', valueType: 'url', protocols: ['https'], value: ['http://www.admiralcloud.com'], error: 'array_atLeastOneValueFailed' },
44
+ { name: 'Array with unique values', type: 'array', value: ['a', 'b', 'a'], unique: true, expected: ['a', 'b'] },
45
+ { name: 'Array with unique objects', type: 'array', value: [{ a: 1, x: true }, { a: 2, x: true }, { a: 2, x: false }, { a: 1, x: true }], unique: true, expected: [{ a: 1, x: true }, { a: 2, x: true }, { a: 2, x: false }] },
44
46
  ]
45
47
 
46
48
  runValidationTests(baseTests, 'array', { equalityCheck: 'eql' })
@@ -18,6 +18,8 @@ module.exports = {
18
18
  { name: 'Valid string from randomValue function', type: 'string', value: randomValue, expected: randomValue },
19
19
  { name: 'Invalid - uppercase vs lowercase', type: 'string', value: 'ABC', enum: ['abc'], error: 'string_notAnAllowedValue' },
20
20
  { name: 'Valid - uppercase vs lowercase', type: 'string', ignoreCase: true, value: 'ABC', enum: ['abc'], expected: 'ABC' },
21
+ { name: 'Invalid - value too short', type: 'string', minLength: 5, value: 'ABC', error: 'string_stringTooShort_minLength5' },
22
+ { name: 'Valid - value is longer than 5 chars', type: 'string', minLength: 5, value: 'ABCDEF', expected: 'ABCDEF' },
21
23
  ]
22
24
 
23
25
  runValidationTests(baseTests, 'string', { equalityCheck: 'eql' })
package/test/tests/url.js CHANGED
@@ -7,7 +7,7 @@ module.exports = {
7
7
  const baseTests = [
8
8
  { name: 'Valid url', type: 'url', value: 'https://www.admiralcloud.com', expected: 'https://www.admiralcloud.com' },
9
9
  { name: 'Invalid url', type: 'url', value: 'www.admiralcloud.com', error: 'url_notAValidURL' },
10
- { name: 'Invalid url - wrong protocol', type: 'url', value: 'ftp://www.admiralcloud.com', error: 'url_notAValidURL' },
10
+ { name: 'Invalid url - wrong protocol', type: 'url', value: 'ftp://www.admiralcloud.com', error: 'url_notAValidURL' }
11
11
  ]
12
12
 
13
13
  runValidationTests(baseTests, 'url')