Add block function

Related to #530

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/actions/attest-build-provenance/issues/530?shareId=XXXX-XXXX-XXXX-XXXX).
This commit is contained in:
Dustin 2025-03-21 00:12:52 -04:00
parent b7ab74091b
commit c947a72caa
3 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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)
})
})
})

View File

@ -18,3 +18,12 @@ export async function run(): Promise<void> {
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')
}