Skip to content

Commit

Permalink
releases/version-2.0.1 (#151)
Browse files Browse the repository at this point in the history
* Removed private tagging to eliminate vscode warning (#148)

* features/support-map-by-util-function (#150)

* Added support for util function mapBy

* Added mapBy documentation

* Updated release version from v2.0.0 to v2.0.1
  • Loading branch information
michaeljymsgutierrez authored Nov 4, 2024
1 parent 2d37263 commit b97d538
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 14 deletions.
21 changes: 18 additions & 3 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ a single object) and performs the following actions:</p>
<li>Updates any relevant request hashes using <code>_pushToRequestHashes</code>.</li>
</ol>
</dd>
<dt><a href="#pushPayload">pushPayload(collectionName, collectionRecords)</a> ⇒ <code>Array</code> | <code>Object</code></dt>
<dt><a href="#pushPayload">pushPayload(collectionName, collectionRecords)</a> ⇒ <code>Array</code> | <code>Object</code></dt>
<dd><p>Pushes records to a collection, aliases, and request hashes.</p>
<p>This method orchestrates the process of adding or updating records
in various data stores within the <code>ApiResourceManager</code>. It takes a
Expand Down Expand Up @@ -428,6 +428,9 @@ specified properties.</p>
<dt><a href="#groupBy">groupBy(objects, groupByProperty)</a> ⇒ <code>Object</code></dt>
<dd><p>Groups objects into arrays based on a specified property.</p>
</dd>
<dt><a href="#mapBy">mapBy(objects, mapByProperty)</a> ⇒ <code>Array.&lt;*&gt;</code></dt>
<dd><p>Maps an array of objects to a new array of values, extracting a specific property from each object.</p>
</dd>
<dt><a href="#firstObject">firstObject([objects])</a> ⇒ <code>Object</code> | <code>undefined</code></dt>
<dd><p>Returns the first object in an array.</p>
</dd>
Expand Down Expand Up @@ -1002,7 +1005,7 @@ a single object) and performs the following actions:

<a name="pushPayload"></a>

## pushPayload(collectionName, collectionRecords) ⇒ <code>Array</code> \| <code>Object</code>
## pushPayload(collectionName, collectionRecords) ⇒ <code>Array</code> \| <code>Object</code>
Pushes records to a collection, aliases, and request hashes.

This method orchestrates the process of adding or updating records
Expand All @@ -1017,7 +1020,6 @@ a single object) and performs the following actions:

**Kind**: global function
**Returns**: <code>Array</code> \| <code>Object</code> - The updated collection records.
**Access**: private

| Param | Type | Description |
| --- | --- | --- |
Expand Down Expand Up @@ -1519,6 +1521,19 @@ Groups objects into arrays based on a specified property.
| objects | <code>Array.&lt;Object&gt;</code> | The array of objects to group. |
| groupByProperty | <code>string</code> | The property to group by. |

<a name="mapBy"></a>

## mapBy(objects, mapByProperty) ⇒ <code>Array.&lt;\*&gt;</code>
Maps an array of objects to a new array of values, extracting a specific property from each object.

**Kind**: global function
**Returns**: <code>Array.&lt;\*&gt;</code> - A new array containing the extracted values.

| Param | Type | Description |
| --- | --- | --- |
| objects | <code>Array.&lt;Object&gt;</code> | The array of objects to map. |
| mapByProperty | <code>string</code> | The property to extract from each object. |

<a name="firstObject"></a>

## firstObject([objects]) ⇒ <code>Object</code> \| <code>undefined</code>
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<p align="center">
<a href="https://www.npmjs.com/package/arm-js-library">
<img src="https://img.shields.io/badge/npm_version-2.0.0-blue" alt="npm-badge-logo" />
<img src="https://img.shields.io/badge/npm_version-2.0.1-blue" alt="npm-badge-logo" />
</a>
<a href="https://github.com/michaeljymsgutierrez/arm-js-library?tab=MIT-1-ov-file">
<img src="https://img.shields.io/badge/license-MIT-green" alt=license"-badge-logo" />
Expand Down Expand Up @@ -732,6 +732,13 @@ const addresses = [
// Returns { school: [{ id: 2 }, { id: 3 }], office: [{ id: 1 }]}
ARM.groupBy(addresses, 'attributes.kind')
```
* **mapBy(objects, mapByProperty)**
* **Maps** an array of objects, extracting a specific property from each.
```javascript
// Returns ['office', 'school', 'school']
ARM.mapBy(addresses, 'attributes.kind')
```

* **firstObject(objects)**
* Returns the **first element** from the given array of objects. If the array is empty, it returns **undefined**.
```javascript
Expand Down
2 changes: 1 addition & 1 deletion apps/create-next-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions packages/dist/arm-js-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import md5 from "md5";
/**
* ARM JavaScript Library
*
* Version: 2.0.0
* Version: 2.0.1
* Date: 2024-05-09 2:19PM GMT+8
*
* @author Michael Jyms Gutierrez
Expand Down Expand Up @@ -894,7 +894,6 @@ Fix: Try adding ${collectionName} on your ARM config initialization.`;
* 3. Updates any relevant aliases using `_pushToAliases`.
* 4. Updates any relevant request hashes using `_pushToRequestHashes`.
*
* @private
* @param {string} collectionName - The name of the collection.
* @param {Array|Object} collectionRecords - The records to be pushed.
* @returns {Array|Object} The updated collection records.
Expand Down Expand Up @@ -1580,6 +1579,15 @@ Fix: Try adding ${collectionName} on your ARM config initialization.`;
groupBy(objects, groupByProperty) {
return groupBy(objects, groupByProperty);
}
/**
* Maps an array of objects to a new array of values, extracting a specific property from each object.
* @param {Array<Object>} objects - The array of objects to map.
* @param {string} mapByProperty - The property to extract from each object.
* @returns {Array<*>} A new array containing the extracted values.
*/
mapBy(objects, mapByProperty) {
return map(objects, mapByProperty);
}
/**
* Returns the first object in an array.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arm-js-library",
"version": "2.0.0",
"version": "2.0.1",
"description": "API Resource Manager",
"type": "module",
"files": [
Expand Down
13 changes: 11 additions & 2 deletions packages/src/lib/api-resource-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* ARM JavaScript Library
*
* Version: 2.0.0
* Version: 2.0.1
* Date: 2024-05-09 2:19PM GMT+8
*
* @author Michael Jyms Gutierrez
Expand Down Expand Up @@ -1090,7 +1090,6 @@ export default class ApiResourceManager {
* 3. Updates any relevant aliases using `_pushToAliases`.
* 4. Updates any relevant request hashes using `_pushToRequestHashes`.
*
* @private
* @param {string} collectionName - The name of the collection.
* @param {Array|Object} collectionRecords - The records to be pushed.
* @returns {Array|Object} The updated collection records.
Expand Down Expand Up @@ -1938,6 +1937,16 @@ export default class ApiResourceManager {
return groupBy(objects, groupByProperty)
}

/**
* Maps an array of objects to a new array of values, extracting a specific property from each object.
* @param {Array<Object>} objects - The array of objects to map.
* @param {string} mapByProperty - The property to extract from each object.
* @returns {Array<*>} A new array containing the extracted values.
*/
mapBy(objects, mapByProperty) {
return map(objects, mapByProperty)
}

/**
* Returns the first object in an array.
*
Expand Down
10 changes: 8 additions & 2 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,11 @@ declare module "arm-js-library" {
* 3. Updates any relevant aliases using `_pushToAliases`.
* 4. Updates any relevant request hashes using `_pushToRequestHashes`.
*
* @private
* @param {string} collectionName - The name of the collection.
* @param {Array|Object} collectionRecords - The records to be pushed.
* @returns {Array|Object} The updated collection records.
*/
private pushPayload;
pushPayload(collectionName: string, collectionRecords: any[] | any): any[] | any;
/**
* Pushes a request and its corresponding response to the request hash store.
*
Expand Down Expand Up @@ -802,6 +801,13 @@ declare module "arm-js-library" {
* are arrays of objects.
*/
groupBy(objects: Array<any>, groupByProperty: string): any;
/**
* Maps an array of objects to a new array of values, extracting a specific property from each object.
* @param {Array<Object>} objects - The array of objects to map.
* @param {string} mapByProperty - The property to extract from each object.
* @returns {Array<*>} A new array containing the extracted values.
*/
mapBy(objects: Array<any>, mapByProperty: string): Array<any>;
/**
* Returns the first object in an array.
*
Expand Down

0 comments on commit b97d538

Please sign in to comment.