Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

objra - Object.replaceAll()

Declarative replaceAll function for Objects

Installation

npm i objra

Usage

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.

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.

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',
//   },
// }

About

Declarative `replaceAll` function for Objects

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.