{"id":19041953,"url":"https://github.com/writetome51/public-array-replacer","last_synced_at":"2025-02-21T22:44:27.774Z","repository":{"id":122062481,"uuid":"156366697","full_name":"writetome51/public-array-replacer","owner":"writetome51","description":"A TypeScript/JavaScript class for replacing array items","archived":false,"fork":false,"pushed_at":"2019-06-10T03:43:42.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T15:15:47.367Z","etag":null,"topics":["array-manipulations","class","elements","items","javascript","replace","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-06T10:31:02.000Z","updated_at":"2019-06-10T03:43:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff013efd-91f9-4864-9006-32ce6fc5663c","html_url":"https://github.com/writetome51/public-array-replacer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-replacer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-replacer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-replacer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fpublic-array-replacer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/writetome51","download_url":"https://codeload.github.com/writetome51/public-array-replacer/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-manipulations","class","elements","items","javascript","replace","typescript"],"created_at":"2024-11-08T22:33:29.798Z","updated_at":"2025-02-21T22:44:27.753Z","avatar_url":"https://github.com/writetome51.png","language":"TypeScript","readme":"# PublicArrayReplacer\n\nAn array-manipulating TypeScript/JavaScript class with methods that replace   \nitems in 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## Methods\n\u003cdetails\u003e\n\u003csummary\u003eview methods\u003c/summary\u003e\n\n```ts\nat(index, newValue): this\n    // Replaces item at index with newValue.  index can be negative or positive.\n\nadjacentAt(startingIndex, newValues: any[]): this\n    // Replaces adjacent items beginning at startingIndex with newValues.\n    // Number of adjacent items that are replaced is same as number of items in \n    // newValues.  startingIndex can be negative or positive.\n    \nbetween(numItemsToKeepAtEachEnd, newValues: any[]): this\n    // Replaces everything between numItemsToKeepAtEachEnd with newValues.\n    // Example: if this.data is [1,2,3,4,5,6,7] , and you call .between(2, [9,10])\n    // this.data will be [1,2,9,10,6,7] .  It preserves the first 2 items and \n    // the last 2.\n```\nNOTICE:  For all the functions below, any parameter called `value` cannot be an object,  \nand any parameter called `values` cannot contain an object.  \nThis does not include arrays. Arrays are OK, as long as they don't contain objects.\n```ts\nadjacentToValue(info: IAdjacentToValueInfo, newValues: any[]): this\n    /**********\n    Replaces adjacent items including, or near a particular value, with newValues.\n    Only applies to the first instance of value found in array.\n    The parameter 'info' is an object that looks like this:\n    {\n        value: any except object (the value to search for in the array),\n        offset: integer (tells function where, in relation to value, to begin \n               selecting adjacent items to replace.  If offset is zero, the \n               selection will begin with value.)\n       \thowMany: integer greater than zero (it's how many adjacent items to replace)\n    }\n    Example:\n\t//  this.data is [1,2,3,4,5,6,7,8] .\n\t//  let newValues = [20,30,40];\n\t//  this.adjacentToValue({value: 5, offset: -1, howMany: 2},  newValues);\n\t//  this.data is now [1,2,3,20,30,40,6,7,8]\n    **********/\n\n    \nfirstOf(value, newValue): this\n    // Replaces first instance of value with newValue.\n    \nfirstOfEach(values: any[], newValues: any[]): this\n    // First instance of values[i] found in array gets replaced with newValues[i].\n    \nallOf(value, newValue): this\n    // Replaces all instances of value with newValue.\n    \nallOfEach(values: any[], newValues: any[]): this\n    // All instances of values[i] found in array get replaced with newValues[i].\n    \neach(replacementFunction: (item, index?, array?) =\u003e any): this\n    /**********\n    Loops thru array, passing each item into replacementFunction.\n    replacementFunction signature:  function(item, index?, array?): any\n    replacementFunction must return the new value you want to give to that item \n    in the array.  Even if you don't want to replace that item, the function \n    must return something or that item will become undefined.\n    Example:\n    //  this.data is [1,2,3,4,5,6] .\n    //  this.each((item) =\u003e {\n    //      if (item === 2 || item === 6) return item * 3;\n    //      else return item;\n    //  });\n    //  this.data is now [1,6,3,4,5,18]\n    **********/\n    \n    \nallWithOne(values: any[], newValue): this\n    // Replaces all instances of each value in values with newValue.\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\n## Usage Examples\n\u003cdetails\u003e\n\u003csummary\u003eview examples\u003c/summary\u003e\n\n```ts\n// changing the array content:\nreplace.data = [1,2,3,4,5,6,7];\n\n// replacing 3 adjacent items starting at index 2:\nreplace.adjacentAt(2, [6, 8, 10]); // replace.data is now [1, 2, 6, 8, 10, 6, 7]\n\nreplace.allWithOne([1,2,6,7], '?'); \n// replace.data is now ['?', '?', '?', 8, 10, '?', '?']\n\nreplace.firstOf(10, {value:10, index: 4});\n// replace.data is now ['?', '?', '?', 8, {value:10, index: 4}, '?', '?']\n\n// Replacing all question marks with zeros, then returning Array:\nlet arr = replace.allOf('?', 0).data;\n// arr is now [0, 0, 0, 8, {value:10, index: 4}, 0, 0]\n```\n\u003c/details\u003e\n\n## Inheritance Chain\n\nPublicArrayReplacer\u003c--[PublicArrayContainer](https://github.com/writetome51/public-array-container#publicarraycontainer)\u003c--[BaseClass](https://github.com/writetome51/typescript-base-class#baseclass)\n\n\n## Installation\n\n```bash\nnpm i  @writetome51/public-array-replacer\n```\n\n## Loading\n```ts\n// If using TypeScript:\nimport {PublicArrayReplacer} from '@writetome51/public-array-replacer';\n// If using ES5 JavaScript:\nvar PublicArrayReplacer = \n        require('@writetome51/public-array-replacer').PublicArrayReplacer;\n```\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-replacer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwritetome51%2Fpublic-array-replacer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fpublic-array-replacer/lists"}