Socket
Socket
Sign inDemoInstall

replacements

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    replacements

Replace strings with other strings


Maintainers
1

Readme

replacements

There is a single class of interest in this project: Replacer.

It is an object for replacing strings with other strings in json-like objects.

The initializer takes a list of assignments, each of which is a dictionary containing a name, a type, and optionally args and kwargs.

There are currently 6 implemented types:

  • identity: returns the argument passed to it.
  • localfile: passes the args and kwargs to open and then reads the file object. The mode is always 'r'.
  • fsspec: passes the args and kwargs to fsspec.open, opens that, and reads. The mode is always 'r'. Requires fsspec to be installed. fsspec has multiple protocols installed, e.g. http(s), (s)ftp and zip. This can also be used for data on S3, if s3fs is installed.
  • awssecret: takes two arguments: region_name and secret_id. Uses boto to call secretsmanager, and returns the returned SecretString.
  • env: takes two arguments: name, and optionally a default value. If the environment variable doesn't exist and no default value was passed, an AssertionError will be raised.
  • base64uuid4: the base64 (the url safe "-_" variant) of a uuid.uuid4 call. Use this to create a unique id that can be used in multiple derived replacements.

Example:

Replacer([{
    "name": "name",
    "type": "identity",
    "args": ["World"]
}])("Hello, ${name}!")

returns "Hello, World!"

There can be dependencies between the assignments. They are resolved linearly using the list order:

Replacer([
    {
        "name": "name",
        "type": "identity",
        "args": ["World"]
    },
    {
        "name": "greeting",
        "type": "identity",
        "args": ["Hello, ${name}!"]
    }
])("${greeting}")

also returns "Hello, World!"

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc