https://github.com/devjiwonchoi/objra
Declarative `replaceAll` function for Objects
https://github.com/devjiwonchoi/objra
object replace replaceall
Last synced: 8 months ago
JSON representation
Declarative `replaceAll` function for Objects
- Host: GitHub
- URL: https://github.com/devjiwonchoi/objra
- Owner: devjiwonchoi
- License: mit
- Created: 2023-07-13T17:39:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-13T19:20:49.000Z (almost 3 years ago)
- Last Synced: 2025-07-25T21:53:19.225Z (9 months ago)
- Topics: object, replace, replaceall
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/objra
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# objra - Object.replaceAll()
Declarative `replaceAll` function for Objects
## Installation
```bash
npm i objra
```
## Usage
```ts
import objectReplaceAll from 'objra'
objectReplaceAll(regexp: string | RegExp, replacement: string, sourceObject: object)
```
**Note: The `replacement` will be available for `string[]` in the near future.**
## Real World Usage
Convert `nullish` values in object to given string.
```js
import objectReplaceAll from 'objra'
const response = fetch(/* ... */)
const data = response.json()
// Replace all null values with empty strings
const dataWithoutNulls = objectReplaceAll(null, '', data)
```
Replace `wildcard` values in object to given string.
```js
import objectReplaceAll from 'objra'
const config = {
'./*': {
types: './dist/*.d.ts',
import: './dist/*.js',
},
}
// This will be simplified in the near future.
const filenames = ['button', 'input', 'checkbox']
const resolvedArray = filenames.map((filename) =>
objectReplaceAll('*', filename, config)
)
const result = Object.assign({}, ...resolvedArray)
// Output:
// {
// './button': {
// types: './dist/button.d.ts',
// import: './dist/button.js',
// },
// './input': {
// types: './dist/input.d.ts',
// import: './dist/input.js',
// },
// './checkbox': {
// types: './dist/checkbox.d.ts',
// import: './dist/checkbox.js',
// },
// }
```