custom-permutation 1.0.3 → 1.0.6

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
@@ -1,43 +1,60 @@
1
1
  # Custom Permutation Generator
2
2
 
3
3
  ```typescript
4
- CustomPermutation(elList: array, choices: { index: array }, nonChoices: { index: array })
4
+ CustomPermutation(elList:[els...], choices:{ index: [els...]] }, nonChoices:{ index: [els...]] })
5
5
  ```
6
6
 
7
- _example:_ `CustomPermutation(['a', 'b', 'c'], {1: ['a', 'b']}, {0: ['a']})`
7
+ _example:_\
8
+ `CustomPermutation(['a', 'b', 'c'], {1: ['a', 'b']}, {0: ['a']})`
8
9
 
9
- _Meaning:_ Permutate 3 elements which are 'a', 'b' and 'c' with below rules
10
+ Permutate 3 elements which are 'a', 'b' and 'c' with below rules
10
11
 
11
- __choices rule: {1: ['a', 'b']}__ For index=1 there can be just 'a' and 'b'
12
- __nonChoices rule: {0: ['a']}__ For index=0 ther can not be element 'a'
12
+ __1. choices rule:__ `{ 1: ['a', 'b'] }`
13
+
14
+ At index=1 there can be just 'a' or 'b'
15
+
16
+ __2. nonChoices rule:__ `{ 0: ['a'] }`
17
+
18
+ At index=0 there can NOT be element 'a'
13
19
 
14
20
  _Note: given index are considered as 0 based: [index=0, index=1, etc]_
15
21
 
16
- What result to be expected in this case:
22
+ __Result set:__
17
23
 
18
- Let's see all permutations, and which ones are valid and not.
19
- - a, b, c : violates nonChoices rule: _first element is 'a', but shouldn't be 'a'_
20
- - a, c, b : violates nonChoices rule: _first element is 'a', but shouldn't be 'a'_
21
- - b, a, c : ok
22
- - b, c, a : violates choices rule: _second element is 'c' but 'a' or 'b' is desired_
23
- - c, a, b : ok
24
- - c, b, a : ok
24
+ Let's see all permutations, and which ones are valid or not.
25
+ - `['a', 'b', 'c']` : violates nonChoices rule: _first element is `'a'`, but shouldn't be `'a'`
26
+ - `['a', 'c', 'b']` : violates nonChoices rule: _first element is `'a'`, but shouldn't be `'a'`_
27
+ - `['b', 'a', 'c']` : ok
28
+ - `['b', 'c', 'a']` : violates choices rule: _second element is `'c'` but `'a'` or `'b'` is desired_
29
+ - `['c', 'a', 'b']` : ok
30
+ - `['c', 'b', 'a']` : ok
25
31
 
26
- So there is just 3 result should be generated for this parameters.
32
+ So there are just 3 results that should be generated with this parameters.
33
+ ```javascript
34
+ let customPerm = new CustomPermutation(['a', 'b', 'c'], { 1: ['a', 'b'] }, { 0: ['a'] });
35
+ let gen = customPerm.generator();
36
+ while (true) {
37
+ let next = gen.next();
38
+ if (next.done) {
39
+ break;
40
+ }
41
+ console.log(next.value)
42
+ }
27
43
 
44
+ ```
45
+ or
28
46
  ```javascript
29
47
  let customPerm = new CustomPermutation(['a', 'b', 'c'], { 1: ['a', 'b'] }, { 0: ['a'] });
30
- let next;
31
48
  while (true) {
32
- next = customPerm.customPermGen.next();
33
- console.log(next);
49
+ let next = customPerm.next();
34
50
  if (!next) {
35
51
  break;
36
52
  }
53
+ console.log(next)
37
54
  }
38
55
  ```
39
56
 
40
- __Console__
41
- ['b', 'a', 'c']
42
- ['c', 'a', 'b']
57
+ __Console__\
58
+ ['b', 'a', 'c']\
59
+ ['c', 'a', 'b']\
43
60
  ['c', 'b', 'a']
@@ -8,4 +8,6 @@ export default class CustomPermutation {
8
8
  private passFn?;
9
9
  customPermGen: CustomPermutationGenerator;
10
10
  constructor(listToPermutate: any[], choices: object, nonChoices: object, elementsOrderAbsolute?: any[], elementsOrderRelative?: any[], passFn?: Function);
11
+ next(): any;
12
+ generator(): Generator<any, void, unknown>;
11
13
  }
@@ -1,4 +1,31 @@
1
1
  "use strict";
2
+ var __generator = (this && this.__generator) || function (thisArg, body) {
3
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
4
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
5
+ function verb(n) { return function (v) { return step([n, v]); }; }
6
+ function step(op) {
7
+ if (f) throw new TypeError("Generator is already executing.");
8
+ while (_) try {
9
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
10
+ if (y = 0, t) op = [op[0] & 2, t.value];
11
+ switch (op[0]) {
12
+ case 0: case 1: t = op; break;
13
+ case 4: _.label++; return { value: op[1], done: false };
14
+ case 5: _.label++; y = op[1]; op = [0]; continue;
15
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
16
+ default:
17
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
18
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
19
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
20
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
21
+ if (t[2]) _.ops.pop();
22
+ _.trys.pop(); continue;
23
+ }
24
+ op = body.call(thisArg, _);
25
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
26
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
27
+ }
28
+ };
2
29
  Object.defineProperty(exports, "__esModule", { value: true });
3
30
  var CustomPermutationGenerator_1 = require("./CustomPermutationGenerator");
4
31
  var CustomPermutation = /** @class */ (function () {
@@ -17,6 +44,30 @@ var CustomPermutation = /** @class */ (function () {
17
44
  }
18
45
  this.customPermGen = new CustomPermutationGenerator_1.CustomPermutationGenerator(listToPermutate, choices, nonChoices, elementsOrderAbsolute, elementsOrderRelative, passFn);
19
46
  }
47
+ CustomPermutation.prototype.next = function () {
48
+ return this.customPermGen.next();
49
+ };
50
+ CustomPermutation.prototype.generator = function () {
51
+ var nextPerm;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ nextPerm = null;
56
+ _a.label = 1;
57
+ case 1:
58
+ if (!true) return [3 /*break*/, 5];
59
+ nextPerm = this.customPermGen.next();
60
+ if (!nextPerm) return [3 /*break*/, 3];
61
+ return [4 /*yield*/, nextPerm];
62
+ case 2:
63
+ _a.sent();
64
+ return [3 /*break*/, 4];
65
+ case 3: return [3 /*break*/, 5];
66
+ case 4: return [3 /*break*/, 1];
67
+ case 5: return [2 /*return*/];
68
+ }
69
+ });
70
+ };
20
71
  return CustomPermutation;
21
72
  }());
22
73
  exports.default = CustomPermutation;
@@ -1 +1 @@
1
- {"version":3,"file":"CustomPermutation.js","sourceRoot":"","sources":["../src/CustomPermutation.ts"],"names":[],"mappings":";;AAAA,2EAA0E;AAE1E;IAGE,2BACU,eAAsB,EACtB,OAAe,EACf,UAAkB,EAClB,qBAA6B,EAC7B,qBAA6B,EAC7B,MAAiB;QALjB,oBAAe,GAAf,eAAe,CAAO;QACtB,YAAO,GAAP,OAAO,CAAQ;QACf,eAAU,GAAV,UAAU,CAAQ;QAClB,0BAAqB,GAArB,qBAAqB,CAAQ;QAC7B,0BAAqB,GAArB,qBAAqB,CAAQ;QAC7B,WAAM,GAAN,MAAM,CAAW;QAGzB,IAAI,CAAC,CAAA,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAE,MAAM,CAAA,EAAE;YAClC,qBAAqB,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,EAAD,CAAC,CAAC,CAAC;SAC/E;QAED,IAAI,CAAC,CAAA,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAE,MAAM,CAAA,EAAE;YAClC,qBAAqB,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,EAAD,CAAC,CAAC,CA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E,MAAM,CAAC,CAAC;IAClJ,CAAC;IAED,gCAAI,GAAJ;QACE,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAEA,qCAAS,GAAV;;;;;oBACM,QAAQ,GAAG,IAAI,CAAC;;;yBAEb,IAAI;oBACT,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;yBACjC,QAAQ,EAAR,wBAAQ;oBACV,qBAAM,QAAQ,EAAA;;oBAAd,SAAc,CAAC;;wBAEf,wBAAM;;;;;KAGX;IAEH,wBAAC;AAAD,CAAC,AAxCD,IAwCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "custom-permutation",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Permutation generator with custom options.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
11
11
  "lint": "tslint -p tsconfig.json",
12
12
  "prepare": "npm run build",
13
- "prepublishOnly": "npm test",
14
- "preversion": "",
13
+ "prepublishOnly": "npm test && npm run preversion",
14
+ "preversion": "true || npm run lint",
15
15
  "version": "npm run format && git add -A src",
16
16
  "postversion": "git push && git push --tags"
17
17
  },