Skip to content

Commit

Permalink
Reorganizes file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenly committed Oct 22, 2024
1 parent 0740f07 commit bf04a27
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ pnpm add @mackenly/zaraz-tools
Currently published on npm and GitHub Packages. If there's another package manager you'd like to see this package on, please let me know by opening an issue.

## Versioning
This project uses [Semantic Versioning](https://semver.org/). For the versions available, see the [tags on this repository](https://github.com/mackenly/zaraz-tools/tags). Furthermore, the project is date versioned allowing you to directly import from an older version if you need to while still being able to get the latest version. For example, if you wanted to import the version from 2024-09-19 and the latest, you could do so like this:
This project uses [Semantic Versioning](https://semver.org/). For the versions available, see the [tags on this repository](https://github.com/mackenly/zaraz-tools/tags).

```javascript
import { Foo } from '@mackenly/zaraz-tools/2024-09-19';
import { Bar } from '@mackenly/zaraz-tools';
import { Foo } from '@mackenly/zaraz-tools';
```

This approach is borrowed from the [@cloudflare/workers-types](https://www.npmjs.com/package/@cloudflare/workers-types) package, but rather than defaulting to the oldest version to ensure compatibility, it defaults to the latest version to ensure you get the latest features and bug fixes. This makes explicit versioning opt-in. You can always fix the version by specifying it in your `package.json`.

## Mocking / Testing Tools
### mockManager
`const mockManager: Manager`
Expand All @@ -72,7 +69,7 @@ const event = {
## Managed Component Utilities
### sha256
`function sha256( data: string, lowercase: boolean = false): Promise<string>`
> This function takes a string and returns a promise that resolves to the SHA-256 hash of the string. The second parameter is a boolean that determines if the hash should be returned in lowercase. By default, the hash is returned in uppercase.
> This function takes a string and returns a promise that resolves to the SHA-256 hash of the string. The second parameter is a boolean that determines if the hash should be lowercased before being hashed. By default, the string is not transformed.
```javascript
import { sha256 } from '@mackenly/zaraz-tools';
Expand Down
4 changes: 2 additions & 2 deletions src/2024-09-19/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mockManager, mockEvent } from "./mocking";
import { sha256 } from "./utils";
import { mockManager, mockEvent } from "../mocking";
import { sha256 } from "../utils/hashing";

export { mockManager, mockEvent, sha256 };
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mockManager, mockEvent, sha256 } from "./2024-09-19";
import { mockManager, mockEvent } from "./mocking";
import { sha256 } from "./utils";

export { mockManager, mockEvent, sha256 };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import * as mocking from './mocking';
import * as mocking from '.';

describe('mocking', async () => {
it('should export mockManager', async () => {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/react/TOOD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Coming soon...
23 changes: 15 additions & 8 deletions src/2024-09-19/utils.test.ts → src/utils/hashing.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
import { describe, it, expect } from 'vitest';
import { sha256 } from './utils';
import { sha256 } from './hashing';

describe('sha256', async () => {
it('should hash an input', async () => {
const input = 'hello';
const input = '[email protected]';
const output = await sha256(input);
expect(output).toBe(
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
'fed93bd41b367d435f8cab3e68285d5141c1207b38ee3a69610aadc74fdcec1e'
);
});

it('should hash an input after lowercasing', async () => {
const input = 'Hello';
const input = '[email protected]';
const output = await sha256(input, true);
expect(output).toBe(
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
'1753bdb368271a785887ddbfb926164f2f7c6a88f609c07ff0401c5572955206'
);
});

it('should hash an input without lowercasing', async () => {
const input = 'Hello';
const input = '[email protected]';
const output = await sha256(input, false);
expect(output).toBe(
'185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969'
'fed93bd41b367d435f8cab3e68285d5141c1207b38ee3a69610aadc74fdcec1e'
);
const output2 = await sha256(input);
expect(output2).toBe(
'185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969'
'fed93bd41b367d435f8cab3e68285d5141c1207b38ee3a69610aadc74fdcec1e'
);
});

// it should return a string
it('should return a string', async () => {
const input = 'hello';
const output = await sha256(input);
expect(typeof output).toBe('string');
});
});
File renamed without changes.
3 changes: 3 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { sha256 } from "./hashing";

export { sha256 };

0 comments on commit bf04a27

Please sign in to comment.