diff --git a/README.md b/README.md index d4f282b..cc92976 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,20 @@ artifact directly into the `subject-digest` input of the attestation action. subject-digest: sha256:${{ steps.upload.outputs.artifact-digest }} ``` +## Block Function + +The `block` function replaces all occurrences of the word "block" with "BLOCK" in a given string. + +### Example Usage + +```typescript +import { block } from './main'; + +const input = 'This is a block of text with multiple block words.'; +const output = block(input); +console.log(output); // This is a BLOCK of text with multiple BLOCK words. +``` + [1]: https://github.com/actions/toolkit/tree/main/packages/attest [2]: https://github.com/in-toto/attestation/tree/main/spec/v1 [3]: https://slsa.dev/spec/v1.0/provenance diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index e437044..b829587 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -154,4 +154,12 @@ describe('main', () => { expect(outputs['predicate-type']).toBe('https://slsa.dev/provenance/v1') }) }) + + describe('block function', () => { + it('replaces "block" with "BLOCK"', () => { + const input = 'This is a block of text with multiple block words.' + const expectedOutput = 'This is a BLOCK of text with multiple BLOCK words.' + expect(main.block(input)).toBe(expectedOutput) + }) + }) }) diff --git a/src/main.ts b/src/main.ts index 0b1f21a..6ee54c9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,3 +18,12 @@ export async function run(): Promise { core.setFailed(error.message) } } + +/** + * Replaces all occurrences of the word "block" with "BLOCK" in the input string. + * @param {string} input - The input string. + * @returns {string} The modified string with "block" replaced by "BLOCK". + */ +export function block(input: string): string { + return input.replace(/block/g, 'BLOCK') +}