@yamato-daiwa/es-extensions 0.9.0-alpha.0 → 0.10.0-alpha.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.
Files changed (60) hide show
  1. package/Distributable/cjs/AJAX/AJAX_Service.js +1 -1
  2. package/Distributable/cjs/Arrays/01-RetrievingOfElements/getLastElementOfArray.js +1 -1
  3. package/Distributable/cjs/Arrays/02-RetrievingOfIndexes/getIndexOfArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne.js +2 -2
  4. package/Distributable/cjs/Arrays/05-ReplacingOfElements/replaceArrayElementsByIndexesImmutably.js +2 -2
  5. package/Distributable/cjs/Arrays/06-PermutationsOfElements/ObjectTypeElementsArrayOrdererByMultipleFields.js +67 -0
  6. package/Distributable/cjs/Arrays/06-PermutationsOfElements/moveArrayElementToOnePosition.js +1 -1
  7. package/Distributable/cjs/Arrays/08-Restructuring/twoDimensionalizeArray.js +4 -4
  8. package/Distributable/cjs/DataMocking/LocalizableMocking/LocalizableEntitiesByIDsMap.js +40 -0
  9. package/Distributable/cjs/DataMocking/LocalizableMocking/LocalizableSampleDataRepository.js +55 -0
  10. package/Distributable/cjs/Maps/getOneEntryOfMap.js +6 -0
  11. package/Distributable/cjs/Numbers/isStringifiedNonNegativeIntegerOfRegularNotation.js +1 -1
  12. package/Distributable/cjs/Objects/getEntriesOfObjectWithFixedKeysSetAndUniformValues.js +6 -0
  13. package/Distributable/cjs/Objects/getObjectPropertySafely.js +26 -24
  14. package/Distributable/cjs/Objects/setObjectProperties.js +51 -0
  15. package/Distributable/cjs/RawObjectDataProcessor/RawObjectDataProcessor.js +259 -147
  16. package/Distributable/cjs/RawObjectDataProcessor/RawObjectDataProcessorLocalization.english.js +52 -67
  17. package/Distributable/cjs/Sets/removeElementsFromSet.js +10 -0
  18. package/Distributable/cjs/Sets/removeThenGetSpecificNumberOfSetElements.js +30 -0
  19. package/Distributable/cjs/Strings/URI/FilesAndDirectories/FileNameExtensions/addPenultimateFileNameExtension.js +36 -0
  20. package/Distributable/cjs/Strings/URI/FilesAndDirectories/FileNameExtensions/removeLastFileNameExtensionFromPath.js +25 -0
  21. package/Distributable/cjs/index.js +28 -7
  22. package/Distributable/esm/AJAX/AJAX_Service.js +1 -1
  23. package/Distributable/esm/Arrays/01-RetrievingOfElements/getLastElementOfArray.js +1 -1
  24. package/Distributable/esm/Arrays/02-RetrievingOfIndexes/getIndexOfArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne.js +2 -2
  25. package/Distributable/esm/Arrays/05-ReplacingOfElements/replaceArrayElementsByIndexesImmutably.js +2 -2
  26. package/Distributable/esm/Arrays/05-ReplacingOfElements/replaceArrayElementsByPredicates.d.ts +2 -2
  27. package/Distributable/esm/Arrays/06-PermutationsOfElements/ObjectTypeElementsArrayOrdererByMultipleFields.d.ts +38 -0
  28. package/Distributable/esm/Arrays/06-PermutationsOfElements/ObjectTypeElementsArrayOrdererByMultipleFields.js +63 -0
  29. package/Distributable/esm/Arrays/06-PermutationsOfElements/moveArrayElementToOnePosition.js +1 -1
  30. package/Distributable/esm/Arrays/08-Restructuring/twoDimensionalizeArray.d.ts +1 -1
  31. package/Distributable/esm/Arrays/08-Restructuring/twoDimensionalizeArray.js +4 -4
  32. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableEntitiesByIDsMap.d.ts +25 -0
  33. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableEntitiesByIDsMap.js +38 -0
  34. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableSampleDataRepository.d.ts +30 -0
  35. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableSampleDataRepository.js +50 -0
  36. package/Distributable/esm/Maps/getOneEntryOfMap.d.ts +1 -0
  37. package/Distributable/esm/Maps/getOneEntryOfMap.js +3 -0
  38. package/Distributable/esm/Numbers/isStringifiedNonNegativeIntegerOfRegularNotation.js +1 -1
  39. package/Distributable/esm/Objects/getEntriesOfObjectWithFixedKeysSetAndUniformValues.d.ts +3 -0
  40. package/Distributable/esm/Objects/getEntriesOfObjectWithFixedKeysSetAndUniformValues.js +3 -0
  41. package/Distributable/esm/Objects/getObjectPropertySafely.d.ts +1 -1
  42. package/Distributable/esm/Objects/getObjectPropertySafely.js +26 -24
  43. package/Distributable/esm/Objects/setObjectProperties.d.ts +5 -0
  44. package/Distributable/esm/Objects/setObjectProperties.js +45 -0
  45. package/Distributable/esm/RawObjectDataProcessor/RawObjectDataProcessor.d.ts +8 -5
  46. package/Distributable/esm/RawObjectDataProcessor/RawObjectDataProcessor.js +259 -147
  47. package/Distributable/esm/RawObjectDataProcessor/RawObjectDataProcessorLocalization.english.js +52 -67
  48. package/Distributable/esm/Sets/removeElementsFromSet.d.ts +9 -0
  49. package/Distributable/esm/Sets/removeElementsFromSet.js +7 -0
  50. package/Distributable/esm/Sets/removeOneElementOfSet.d.ts +8 -8
  51. package/Distributable/esm/Sets/removeThenGetSpecificNumberOfSetElements.d.ts +16 -0
  52. package/Distributable/esm/Sets/removeThenGetSpecificNumberOfSetElements.js +24 -0
  53. package/Distributable/esm/Strings/URI/FilesAndDirectories/FileNameExtensions/addPenultimateFileNameExtension.d.ts +6 -0
  54. package/Distributable/esm/Strings/URI/FilesAndDirectories/FileNameExtensions/addPenultimateFileNameExtension.js +30 -0
  55. package/Distributable/esm/Strings/URI/FilesAndDirectories/FileNameExtensions/removeLastFileNameExtensionFromPath.d.ts +1 -0
  56. package/Distributable/esm/Strings/URI/FilesAndDirectories/FileNameExtensions/removeLastFileNameExtensionFromPath.js +19 -0
  57. package/Distributable/esm/index.d.ts +12 -2
  58. package/Distributable/esm/index.js +11 -1
  59. package/README.md +1636 -60
  60. package/package.json +8 -8
@@ -139,7 +139,7 @@ class AJAX_Service {
139
139
  Logger_1.default.throwErrorWithFormattedMessage({
140
140
  errorInstance: new InvalidConfigError_1.default({
141
141
  customMessage: "The \"alternatingURI_PathPart\" has been specified while the static field " +
142
- "\"API_SERVER_URI_CONSTANT_PART\" has not been set."
142
+ "\"API_SERVER_URI_CONSTANT_PART__WITHOUT_TRAILING_SLASH\" has not been set."
143
143
  }),
144
144
  title: InvalidConfigError_1.default.localization.defaultTitle,
145
145
  occurrenceLocation: "AJAX_Service.normalizeURI_UntilPath(URI_PathRawDefinition)"
@@ -12,7 +12,7 @@ function getLastElementOfArray(targetArray, options) {
12
12
  if ((0, isUndefined_1.default)(lastElementOfTargetArray)) {
13
13
  if (options?.mustThrowErrorIfArrayIsEmpty === true) {
14
14
  Logger_1.default.throwErrorWithFormattedMessage({
15
- errorInstance: new UnexpectedEventError_1.default("Contrary to expectations, target array is empty thus there is no the last element could be accessed."),
15
+ errorInstance: new UnexpectedEventError_1.default("Contrary to expectations, target array is empty thus there is no the last element can be accessed."),
16
16
  title: UnexpectedEventError_1.default.localization.defaultTitle,
17
17
  occurrenceLocation: "getLastElementOfArray(targetArray, options)"
18
18
  });
@@ -27,8 +27,8 @@ function getIndexOfArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne(ta
27
27
  if (indexesOfAllElementsSatisfiesThePredicate.length > 1) {
28
28
  if (options.mustThrowErrorIfElementNotFoundOrMatchesAreMultiple === true) {
29
29
  Logger_1.default.throwErrorWithFormattedMessage({
30
- errorInstance: new UnexpectedEventError_1.default("There are multiple elements satisfies the predicate. As it follows from the function name, two or more " +
31
- "matches case is being considered as unexpected event."),
30
+ errorInstance: new UnexpectedEventError_1.default("There are multiple elements satisfies the predicate. " +
31
+ "As it follows from the function name, two or more matches case is being considered as unexpected event."),
32
32
  title: UnexpectedEventError_1.default.localization.defaultTitle,
33
33
  occurrenceLocation: "getIndexOfArrayElementSatisfiesThePredicateIfSuchElementIsExactlyOne" +
34
34
  "(targetArray, predicate, options)"
@@ -27,11 +27,11 @@ function replaceArrayElementsByIndexesImmutably(sourceDataAndOptions) {
27
27
  "● The combination of:\n " +
28
28
  "○ \"index\": must the either natural number or 0\n" +
29
29
  "○ \"newElement\": must corresponding to type of elements of the target array\n" +
30
- "● \"replacements\": The array of objects with above \"index\" and \"newElement\" properties and same " +
30
+ "● \"replacements\": the array of objects with above \"index\" and \"newElement\" properties and same " +
31
31
  "limitations"
32
32
  }),
33
33
  title: InvalidParameterValueError_1.default.localization.defaultTitle,
34
- occurrenceLocation: "addElementsToArray(compoundParameter)"
34
+ occurrenceLocation: "replaceArrayElementsByIndexesImmutably(sourceDataAndOptions)"
35
35
  });
36
36
  }
37
37
  for (const replacement of replacements) {
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectTypeElementsArrayOrdererByMultipleFields = void 0;
4
+ class ObjectTypeElementsArrayOrdererByMultipleFields {
5
+ static order({ targetArray, mutably, elementsComparers, finalElementsStableComparer }) {
6
+ const arrayWorkpiece = mutably ? targetArray : [...targetArray];
7
+ if (arrayWorkpiece.length < 2 || elementsComparers.length === 0) {
8
+ return arrayWorkpiece;
9
+ }
10
+ let similarElementsGroups = ObjectTypeElementsArrayOrdererByMultipleFields.assignMultipleElementsToGroups(arrayWorkpiece, elementsComparers[0]);
11
+ for (const compareElements of elementsComparers.slice(1)) {
12
+ similarElementsGroups =
13
+ ObjectTypeElementsArrayOrdererByMultipleFields.updateGroups(similarElementsGroups, compareElements);
14
+ }
15
+ similarElementsGroups =
16
+ ObjectTypeElementsArrayOrdererByMultipleFields.updateGroups(similarElementsGroups, finalElementsStableComparer);
17
+ return similarElementsGroups.flatMap((group) => group.elements);
18
+ }
19
+ static updateGroups(groups, compareElements) {
20
+ const updatedGroups = [];
21
+ for (const group of groups) {
22
+ if (group.elements.length === 1) {
23
+ updatedGroups.push({ elements: [...group.elements] });
24
+ continue;
25
+ }
26
+ updatedGroups.push(...ObjectTypeElementsArrayOrdererByMultipleFields.assignMultipleElementsToGroups(group.elements, compareElements));
27
+ }
28
+ return updatedGroups;
29
+ }
30
+ static assignMultipleElementsToGroups(elementsOfParentGroup, compareElements) {
31
+ const groups = [{ elements: [elementsOfParentGroup[0]] }];
32
+ for (let index = 1; index < elementsOfParentGroup.length; index++) {
33
+ const targetElement = elementsOfParentGroup[index];
34
+ let hasCurrentElementBeenAssignedToGroup = false;
35
+ let wasFirstElementGreaterThanSecondOne = false;
36
+ for (const [groupIndex, group] of groups.entries()) {
37
+ const comparisonResult = compareElements(targetElement, group.elements[0]);
38
+ if (Reflect.get(comparisonResult, "firstElementIsStrictlyGreater") === true) {
39
+ wasFirstElementGreaterThanSecondOne = true;
40
+ }
41
+ else if ("elementsAreEquals" in comparisonResult) {
42
+ group.elements.push(targetElement);
43
+ hasCurrentElementBeenAssignedToGroup = true;
44
+ break;
45
+ }
46
+ else {
47
+ if (wasFirstElementGreaterThanSecondOne) {
48
+ groups.splice(groupIndex, 0, { elements: [targetElement] });
49
+ hasCurrentElementBeenAssignedToGroup = true;
50
+ break;
51
+ }
52
+ }
53
+ }
54
+ if (!hasCurrentElementBeenAssignedToGroup) {
55
+ if (wasFirstElementGreaterThanSecondOne) {
56
+ groups.push({ elements: [targetElement] });
57
+ }
58
+ else {
59
+ groups.unshift({ elements: [targetElement] });
60
+ }
61
+ }
62
+ }
63
+ return groups;
64
+ }
65
+ }
66
+ exports.ObjectTypeElementsArrayOrdererByMultipleFields = ObjectTypeElementsArrayOrdererByMultipleFields;
67
+ exports.default = ObjectTypeElementsArrayOrdererByMultipleFields.order;
@@ -15,7 +15,7 @@ function moveArrayElementToOnePosition({ mutably, targetArray, toLeft, errorMust
15
15
  errorInstance: new InvalidParameterValueError_1.default({
16
16
  parameterNumber: 1,
17
17
  parameterName: "sourceDataAndOptions",
18
- messageSpecificPart: `Target array must contain at least 2 elements while actually contains ${targetArray.length}. ` +
18
+ messageSpecificPart: `Target array must contain at least 2 elements while actually contains ${targetArray.length} ones. ` +
19
19
  "This case is being considered as an error when \"errorMustBeThrownIf.elementsCountIsLessThan2\" " +
20
20
  "flag has been set to \"true\"."
21
21
  }),
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = twoDimensionalizeArray;
4
- function twoDimensionalizeArray(sourceData) {
4
+ function twoDimensionalizeArray({ targetFlatArray, elementsCountPerNestedArray }) {
5
5
  const twoDimensionalArray = [];
6
- const elementsCountInTargetFlatArray = sourceData.targetFlatArray.length;
6
+ const elementsCountInTargetFlatArray = targetFlatArray.length;
7
7
  let nestedArray = [];
8
- for (const [index, arrayElement] of sourceData.targetFlatArray.entries()) {
8
+ for (const [index, arrayElement] of targetFlatArray.entries()) {
9
9
  nestedArray.push(arrayElement);
10
10
  const hasNextElement = index !== elementsCountInTargetFlatArray - 1;
11
11
  if (hasNextElement) {
12
- if (nestedArray.length === sourceData.elementsCountPerNestedArray) {
12
+ if (nestedArray.length === elementsCountPerNestedArray) {
13
13
  twoDimensionalArray.push(nestedArray);
14
14
  nestedArray = [];
15
15
  }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class LocalizableEntitiesByIDsMap extends Map {
4
+ getEntityID;
5
+ constructor({ initialEntitiesWithLocalizations, getEntityID }) {
6
+ super((initialEntitiesWithLocalizations ?? []).
7
+ map(({ entity, localizations }) => [
8
+ getEntityID(entity),
9
+ {
10
+ entity,
11
+ localizations
12
+ }
13
+ ]));
14
+ this.getEntityID = getEntityID;
15
+ }
16
+ addEntityWithLocalization({ entity, localizations }) {
17
+ super.set(this.getEntityID(entity), {
18
+ entity,
19
+ localizations
20
+ });
21
+ }
22
+ addEntitiesWithLocalizations(entitiesWithLocalization) {
23
+ for (const { entity, localizations } of entitiesWithLocalization) {
24
+ this.set(this.getEntityID(entity), { entity, localizations });
25
+ }
26
+ }
27
+ }
28
+ (function (LocalizableEntitiesByIDsMap) {
29
+ let EntityWithLocalizations;
30
+ (function (EntityWithLocalizations) {
31
+ function createLocalizations(localizationsKeysEnumeration, createLocalization) {
32
+ return Object.values(localizationsKeysEnumeration).reduce((interimLocalizations, localizationKey) => {
33
+ interimLocalizations[localizationKey] = createLocalization(localizationKey);
34
+ return interimLocalizations;
35
+ }, {});
36
+ }
37
+ EntityWithLocalizations.createLocalizations = createLocalizations;
38
+ })(EntityWithLocalizations = LocalizableEntitiesByIDsMap.EntityWithLocalizations || (LocalizableEntitiesByIDsMap.EntityWithLocalizations = {}));
39
+ })(LocalizableEntitiesByIDsMap || (LocalizableEntitiesByIDsMap = {}));
40
+ exports.default = LocalizableEntitiesByIDsMap;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const LocalizableEntitiesByIDsMap_1 = __importDefault(require("./LocalizableEntitiesByIDsMap"));
7
+ const Logger_1 = __importDefault(require("../../Logging/Logger"));
8
+ const UnexpectedEventError_1 = __importDefault(require("../../Errors/UnexpectedEvent/UnexpectedEventError"));
9
+ const isUndefined_1 = __importDefault(require("../../TypeGuards/EmptyTypes/isUndefined"));
10
+ const getEntriesOfObjectWithFixedKeysSetAndUniformValues_1 = __importDefault(require("../../Objects/getEntriesOfObjectWithFixedKeysSetAndUniformValues"));
11
+ class LocalizableSampleDataRepository {
12
+ cachedSamplesWithLocalizationsByHumanFriendlyIDs;
13
+ get entitiesCount() {
14
+ return Object.entries(this.workpieces).length;
15
+ }
16
+ assignIDsAndGetLocalizableEntitiesMap({ preGeneratedIDs, mustCacheGeneratedSamples }) {
17
+ let samplesWithLocalizationsByHumanFriendlyIDs;
18
+ if ((0, isUndefined_1.default)(this.cachedSamplesWithLocalizationsByHumanFriendlyIDs)) {
19
+ const iterativelyGeneratedSamplesWithLocalizationByHumanFriendlyIDs = (0, getEntriesOfObjectWithFixedKeysSetAndUniformValues_1.default)(this.workpieces).
20
+ reduce((interimSamplesWithLocalizationByHumanFriendlyIDs, [humanReadableIDs, workpiece], index) => {
21
+ interimSamplesWithLocalizationByHumanFriendlyIDs[humanReadableIDs] =
22
+ this.completeWorkpiece(preGeneratedIDs[index], workpiece);
23
+ return interimSamplesWithLocalizationByHumanFriendlyIDs;
24
+ }, {});
25
+ samplesWithLocalizationsByHumanFriendlyIDs =
26
+ iterativelyGeneratedSamplesWithLocalizationByHumanFriendlyIDs;
27
+ }
28
+ else {
29
+ samplesWithLocalizationsByHumanFriendlyIDs = this.cachedSamplesWithLocalizationsByHumanFriendlyIDs;
30
+ }
31
+ if (mustCacheGeneratedSamples) {
32
+ this.cachedSamplesWithLocalizationsByHumanFriendlyIDs = samplesWithLocalizationsByHumanFriendlyIDs;
33
+ }
34
+ return new LocalizableEntitiesByIDsMap_1.default({
35
+ getEntityID: this.getEntityID.bind(this),
36
+ initialEntitiesWithLocalizations: Object.values(samplesWithLocalizationsByHumanFriendlyIDs)
37
+ });
38
+ }
39
+ getExpectedBeInitializedSamplesWithLocalizationsByHumanFriendlyIDs() {
40
+ return this.cachedSamplesWithLocalizationsByHumanFriendlyIDs ??
41
+ Logger_1.default.throwErrorWithFormattedMessage({
42
+ errorInstance: new UnexpectedEventError_1.default("Contrary to expectations, the samples with localizations by human friendly IDs map has not been initialized."),
43
+ title: UnexpectedEventError_1.default.localization.defaultTitle,
44
+ occurrenceLocation: "InheritorOf<LocalizableSamplesRepository>." +
45
+ "getExpectedBeInitializedSamplesWithLocalizationsByHumanFriendlyIDs(compoundParameter)"
46
+ });
47
+ }
48
+ static createLocalizations(workpiece, getLocaleDependentFields, composeLocalization) {
49
+ return (0, getEntriesOfObjectWithFixedKeysSetAndUniformValues_1.default)(getLocaleDependentFields(workpiece)).reduce((interimLocalizations, [languageBCP_47_Subtag, localeDependentFields]) => {
50
+ interimLocalizations[languageBCP_47_Subtag] = composeLocalization(languageBCP_47_Subtag, localeDependentFields);
51
+ return interimLocalizations;
52
+ }, {});
53
+ }
54
+ }
55
+ exports.default = LocalizableSampleDataRepository;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getOneEntryOfMap;
4
+ function getOneEntryOfMap(targetMap) {
5
+ return Array.from(targetMap.entries())[0];
6
+ }
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = isStringifiedNonNegativeIntegerOfRegularNotation;
4
4
  function isStringifiedNonNegativeIntegerOfRegularNotation(value) {
5
- return (/^[1-9]\d*$/u).test(value);
5
+ return (/^(?:0|^[1-9]\d*)$/u).test(value);
6
6
  }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getEntriesOfObjectWithFixedKeysSetAndUniformValues;
4
+ function getEntriesOfObjectWithFixedKeysSetAndUniformValues(targetObject) {
5
+ return Object.entries(targetObject);
6
+ }
@@ -9,44 +9,46 @@ const Logger_1 = __importDefault(require("../Logging/Logger"));
9
9
  const InvalidParameterValueError_1 = __importDefault(require("../Errors/InvalidParameterValue/InvalidParameterValueError"));
10
10
  const isNonEmptyString_1 = __importDefault(require("../TypeGuards/Strings/isNonEmptyString"));
11
11
  const isArbitraryObject_1 = __importDefault(require("../TypeGuards/Objects/isArbitraryObject"));
12
+ const isNaturalNumberOrZero_1 = __importDefault(require("../TypeGuards/Numbers/isNaturalNumberOrZero"));
12
13
  function getObjectPropertySafely(targetObject, dotSeparatedOrArrayedPathToTargetProperty) {
13
- if (!(0, isNonEmptyString_1.default)(dotSeparatedOrArrayedPathToTargetProperty) &&
14
- (!Array.isArray(dotSeparatedOrArrayedPathToTargetProperty) ||
15
- dotSeparatedOrArrayedPathToTargetProperty.some((key) => !(0, isNonEmptyString_1.default)(key)))) {
16
- Logger_1.default.logError({
17
- errorType: InvalidParameterValueError_1.default.NAME,
18
- title: InvalidParameterValueError_1.default.localization.defaultTitle,
19
- description: InvalidParameterValueError_1.default.localization.generateDescription({
20
- parameterNumber: 2,
21
- parameterName: "dotSeparatedOrArrayedPathToTargetProperty",
22
- messageSpecificPart: "This parameter must be either non-empty string or array of non-empty strings."
23
- }),
24
- occurrenceLocation: "getObjectPropertySafely(targetObject, dotSeparatedOrArrayedPathToTargetProperty)"
25
- });
26
- return;
27
- }
28
14
  if (!(0, isArbitraryObject_1.default)(targetObject)) {
29
15
  return;
30
16
  }
31
17
  let targetPropertyPathSegments;
32
- if (Array.isArray(dotSeparatedOrArrayedPathToTargetProperty)) {
18
+ if (Array.isArray(dotSeparatedOrArrayedPathToTargetProperty) &&
19
+ dotSeparatedOrArrayedPathToTargetProperty.length > 0 &&
20
+ dotSeparatedOrArrayedPathToTargetProperty.
21
+ every((key) => (0, isNonEmptyString_1.default)(key) || (0, isNaturalNumberOrZero_1.default)(key))) {
33
22
  targetPropertyPathSegments = dotSeparatedOrArrayedPathToTargetProperty;
34
23
  }
35
- else {
24
+ else if ((0, isNaturalNumberOrZero_1.default)(dotSeparatedOrArrayedPathToTargetProperty)) {
25
+ targetPropertyPathSegments = [String(dotSeparatedOrArrayedPathToTargetProperty)];
26
+ }
27
+ else if ((0, isNonEmptyString_1.default)(dotSeparatedOrArrayedPathToTargetProperty)) {
36
28
  targetPropertyPathSegments = (0, splitString_1.default)(dotSeparatedOrArrayedPathToTargetProperty, ".");
37
29
  }
38
- if (targetPropertyPathSegments.length === 0) {
30
+ else {
31
+ Logger_1.default.throwErrorWithFormattedMessage({
32
+ errorInstance: new InvalidParameterValueError_1.default({
33
+ parameterNumber: 2,
34
+ parameterName: "dotSeparatedOrArrayedPathToTargetProperty",
35
+ messageSpecificPart: "This parameter must be either a non-empty string, or a non-negative integer, or a non-empty array " +
36
+ "of strings and/or non-negative integers."
37
+ }),
38
+ title: InvalidParameterValueError_1.default.localization.defaultTitle,
39
+ occurrenceLocation: "getObjectPropertySafely(targetObject, dotSeparatedOrArrayedPathToTargetProperty)"
40
+ });
39
41
  return;
40
42
  }
41
43
  let objectOfCurrentDepthLevel = targetObject;
42
- for (let depthLevel = 1; depthLevel <= targetPropertyPathSegments.length; depthLevel++) {
43
- const isLastDepthLevel = depthLevel === targetPropertyPathSegments.length;
44
- const valueOfNextDepthLevel = objectOfCurrentDepthLevel[targetPropertyPathSegments[depthLevel - 1]];
44
+ for (let depthLevel__numerationFrom1 = 1; depthLevel__numerationFrom1 <= targetPropertyPathSegments.length; depthLevel__numerationFrom1++) {
45
+ const isLastDepthLevel = depthLevel__numerationFrom1 === targetPropertyPathSegments.length;
46
+ const valueOfCurrentDepthLevel = objectOfCurrentDepthLevel[targetPropertyPathSegments[depthLevel__numerationFrom1 - 1]];
45
47
  if (isLastDepthLevel) {
46
- return valueOfNextDepthLevel;
48
+ return valueOfCurrentDepthLevel;
47
49
  }
48
- else if ((0, isArbitraryObject_1.default)(valueOfNextDepthLevel)) {
49
- objectOfCurrentDepthLevel = valueOfNextDepthLevel;
50
+ else if ((0, isArbitraryObject_1.default)(valueOfCurrentDepthLevel)) {
51
+ objectOfCurrentDepthLevel = valueOfCurrentDepthLevel;
50
52
  }
51
53
  else {
52
54
  return;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = setObjectProperties;
7
+ const splitString_1 = __importDefault(require("../Strings/splitString"));
8
+ const isNonNullObject_1 = __importDefault(require("../TypeGuards/Objects/isNonNullObject"));
9
+ const isUndefined_1 = __importDefault(require("../TypeGuards/EmptyTypes/isUndefined"));
10
+ const isStringifiedNonNegativeIntegerOfRegularNotation_1 = __importDefault(require("../Numbers/isStringifiedNonNegativeIntegerOfRegularNotation"));
11
+ function setObjectProperties(targetObject, order) {
12
+ for (const [fullyQualifiedName, propertyDescriptor] of Object.entries(order)) {
13
+ const targetPropertyPathSegments = (0, splitString_1.default)(fullyQualifiedName, ".");
14
+ let objectOfCurrentDepthLevel = targetObject;
15
+ for (let depthLevel__numerationFrom1 = 1; depthLevel__numerationFrom1 <= targetPropertyPathSegments.length; depthLevel__numerationFrom1++) {
16
+ const isLastDepthLevel = depthLevel__numerationFrom1 === targetPropertyPathSegments.length;
17
+ const propertyKeyForCurrentDepthLevel = targetPropertyPathSegments[depthLevel__numerationFrom1 - 1];
18
+ let valueOfNextDepthLevel = Reflect.get(objectOfCurrentDepthLevel, propertyKeyForCurrentDepthLevel);
19
+ if (isLastDepthLevel) {
20
+ if ((0, isNonNullObject_1.default)(objectOfCurrentDepthLevel)) {
21
+ Object.defineProperty(objectOfCurrentDepthLevel, propertyKeyForCurrentDepthLevel, {
22
+ value: propertyDescriptor.value,
23
+ enumerable: propertyDescriptor.enumerable ?? true,
24
+ configurable: propertyDescriptor.configurable ?? true,
25
+ writable: propertyDescriptor.writable ?? true
26
+ });
27
+ }
28
+ else {
29
+ return;
30
+ }
31
+ }
32
+ else if ((0, isNonNullObject_1.default)(valueOfNextDepthLevel)) {
33
+ objectOfCurrentDepthLevel = valueOfNextDepthLevel;
34
+ }
35
+ else if ((0, isUndefined_1.default)(valueOfNextDepthLevel) && propertyDescriptor.mustCreateParentsObjectsIfNotPresent === true) {
36
+ const propertyKeyForNextDepthLevel = targetPropertyPathSegments[depthLevel__numerationFrom1];
37
+ valueOfNextDepthLevel = (0, isStringifiedNonNegativeIntegerOfRegularNotation_1.default)(propertyKeyForNextDepthLevel) ? [] : {};
38
+ Object.defineProperty(objectOfCurrentDepthLevel, propertyKeyForCurrentDepthLevel, {
39
+ value: valueOfNextDepthLevel,
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true
43
+ });
44
+ objectOfCurrentDepthLevel = valueOfNextDepthLevel;
45
+ }
46
+ else {
47
+ return;
48
+ }
49
+ }
50
+ }
51
+ }