{"id":19041971,"url":"https://github.com/writetome51/public-array-getter","last_synced_at":"2025-02-21T22:44:27.970Z","repository":{"id":122062446,"uuid":"153697241","full_name":"writetome51/public-array-getter","owner":"writetome51","description":"An array-manipulating Typescript/Javascript class with methods that return items copied from the array","archived":false,"fork":false,"pushed_at":"2019-06-09T23:32:26.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T22:55:31.395Z","etag":null,"topics":["array","array-manipulations","get","get-items","items","javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/writetome51.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-10-18T22:54:49.000Z","updated_at":"2020-05-24T16:39:13.000Z","dependencies_parsed_at":"2023-07-25T07:02:03.714Z","dependency_job_id":null,"html_url":"https://github.com/writetome51/public-array-getter","commit_stats":null,"previous_names":["writetome51/open-array-item-getter","writetome51/public-array-item-getter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-getter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-getter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-getter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-getter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/writetome51","download_url":"https://codeload.github.com/writetome51/public-array-getter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100512,"owners_count":19747683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","array-manipulations","get","get-items","items","javascript","typescript"],"created_at":"2024-11-08T22:33:36.291Z","updated_at":"2025-02-21T22:44:27.938Z","avatar_url":"https://github.com/writetome51.png","language":"TypeScript","readme":"# PublicArrayGetter \n\nAn array-manipulating Typescript/Javascript class with methods that return items copied   \nfrom the array. None of the methods modify the array.\n\n## Constructor\n```ts\nconstructor(data? = []) //  'data' is assigned to this.data .\n```\n\nYou can reset the array by accessing the class `.data` property:\n```ts\nthis.data = [1,2,3,4];\n```\n\n## Properties\n```ts\ndata : any[]  // the actual array\n\nclassName: string (read-only)\n```\n\n\n## Methods\n\u003cdetails\u003e\n\u003csummary\u003eview methods\u003c/summary\u003e\n\n```ts\ncopy(): any[]\n    // returns independent copy of this.data .\n\nbyIndex(index): any\n    // returns item identified by `index`.  `index` can be negative or positive.\n    \nbyIndexes(indexes): any[]\n    // returns items identified by `indexes`.  `indexes` can be negative or positive.\n\nhead(numItems): any[]\n    // returns `numItems` from beginning of this.data\n\ntail(numItems): any[]\n    // returns `numItems` from end of this.data\n\nbetween(numItemsToIgnoreAtEachEnd): any[]\n    // Returns everything between `numItemsToIgnoreAtEachEnd` in this.data\n    // Example:\n    // let get = new PublicArrayGetter( [1,2,3,4,5,6,7,8,9,10] );\n    // get.between(2); // returns everything between first 2 and last 2 items.\n    // --\u003e [3,4,5,6,7,8]\n\nadjacentAt(startingIndex, howMany): any[]\n    // Beginning at `startingIndex`, returns `howMany` adjacent items from this.data.\n    // startingIndex can be negative or positive.\n```       \nNOTICE: For all the methods below, any parameter called `value` cannot be an object.  \nThis does not include arrays. Arrays are OK, as long as they don't contain objects.\n```ts\nadjacentToValue(\n    {\n        value: any except object,\n        offset: integer,\n        howMany: integer greater than zero\n    }\n): any[]\n    /************\n    Returns `howMany` adjacent items from this.data, starting with, or close to, `value`.\n    Exactly where the selection starts is decided by `offset`, which is the position,\n    relative to `value`, where to begin the selection. For example, if `offset` is 0,\n    then the selection begins at `value`.  If -1, it begins one place to the left of\n    `value`.  If 1, it begins one place to the right.\n    Note: the function only works with the first found instance of `value`.\n    Example:\n        let get = new PublicArrayGetter( [1,2,3,4,5,6,7,8,9,10] );\n        let numbers = get.adjacentToValue({value:5, offset: -2, howMany:3});\n        // numbers is now [3,4,5]\n    *************/\n\nallAfterFirst(value): any[]\n    // returns all items after first instance of `value`.\n\nallBeforeFirst(value): any[]\n    // returns all items before first instance of `value`.\n\nallAfterLast(value): any[]\n    // returns all items after last instance of `value`.\n\nallBeforeLast(value): any[]\n    // returns all items before last instance of `value`.\n\nuniqueItems(): any[]\n    // returns no duplicates.\n\nduplicates(): any[]\n    // returns every instance of a duplicate, so you may get multiple instances.\n\nshuffled(): any[]\n    // returns new version of this.data with order of items randomized.\n```        \nThe next 2 methods return an array of IValueIndexPairs.  \nA IValueIndexPair is this object: `{value: any, index: integer}`  \nIt represents an array item's value and index.\n```ts\nbyTest(testFunction: ((currentItem, currentIndex?, array?) =\u003e boolean)): IValueIndexPair[]\n    // Almost exactly like Array.filter(), except it returns array of IValueIndexPairs.\n     \nbyType(\n    type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined' | 'null'\n):  IValueIndexPair[] \n    // returns all items that match `type`. \n    // Here, 'null' is considered its own type, separate from 'object'.\n    // You can also pass 'array' as a type.  Passing 'object' will match with objects and arrays.\n``` \nThe methods below are not important to know about in order to use this  \nclass.  They're inherited from [BaseClass](https://github.com/writetome51/typescript-base-class#baseclass) .\n``` ts\nprotected   _createGetterAndOrSetterForEach(\n\t\tpropertyNames: string[],\n\t\tconfiguration: IGetterSetterConfiguration\n\t   ) : void\n    /*********************\n    Use this method when you have a bunch of properties that need getter and/or \n    setter functions that all do the same thing. You pass in an array of string \n    names of those properties, and the method attaches the same getter and/or \n    setter function to each property.\n    IGetterSetterConfiguration is this object:\n    {\n        get_setterFunction?: (\n             propertyName: string, index?: number, propertyNames?: string[]\n        ) =\u003e Function,\n\t    // get_setterFunction takes the property name as first argument and \n\t    // returns the setter function.  The setter function must take one \n\t    // parameter and return void.\n\t    \n        get_getterFunction?: (\n             propertyName: string, index?: number, propertyNames?: string[]\n        ) =\u003e Function\n\t    // get_getterFunction takes the property name as first argument and \n\t    // returns the getter function.  The getter function must return something.\n    }\n    *********************/ \n\n\nprotected   _returnThis_after(voidExpression: any) : this\n    // voidExpression is executed, then function returns this.\n    // Even if voidExpression returns something, the returned data isn't used.\n\nprotected   _errorIfPropertyHasNoValue(\n                property: string, // can contain dot-notation, i.e., 'property.subproperty'\n                propertyNameInError? = ''\n            ) : void\n    // If value of this[property] is undefined or null, it triggers fatal error:\n    // `The property \"${propertyNameInError}\" has no value.`\n```\n\u003c/details\u003e\n\n## Inheritance Chain\n\nPublicArrayGetter\u003c--[PublicArrayContainer](https://github.com/writetome51/public-array-container#publicarraycontainer)\u003c--[BaseClass](https://github.com/writetome51/typescript-base-class#baseclass)\n\n## Installation\n\n`npm i @writetome51/public-array-getter`\n\n## Loading\n```ts\n// if using Typescript:\nimport { PublicArrayGetter } from '@writetome51/public-array-getter';\n// if using ES5 Javascript:\nvar PublicArrayGetter = require('@writetome51/public-array-getter').PublicArrayGetter;\n```\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fpublic-array-getter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwritetome51%2Fpublic-array-getter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fpublic-array-getter/lists"}