@itreg/shuffle-array 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST_TEMPLATE.md +40 -0
- package/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md +58 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +61 -0
- package/CONTRIBUTING.md +49 -0
- package/LICENSE.md +22 -0
- package/README.md +77 -0
- package/SECURITY.md +38 -0
- package/jest.config.js +10 -0
- package/package.json +33 -0
- package/src/index.js +6 -0
- package/test/index.spec.js +19 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "Feature Request"
|
|
3
|
+
about: "Suggest a new feature or enhancement"
|
|
4
|
+
title: ""
|
|
5
|
+
labels: "feature"
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Summary
|
|
10
|
+
|
|
11
|
+
<!--
|
|
12
|
+
Please provide a short summary of the feature or enhancement you'd like to see.
|
|
13
|
+
-->
|
|
14
|
+
|
|
15
|
+
## Motivation
|
|
16
|
+
|
|
17
|
+
<!--
|
|
18
|
+
Explain why this feature would be useful. Are you facing any limitations or is it filling a gap?
|
|
19
|
+
Try to provide a clear use-case.
|
|
20
|
+
-->
|
|
21
|
+
|
|
22
|
+
## Proposed Solution
|
|
23
|
+
|
|
24
|
+
<!--
|
|
25
|
+
Describe your idea of how you’d like this feature to function.
|
|
26
|
+
It’s helpful to be as specific as possible.
|
|
27
|
+
Feel free to add mockups or pseudo-code.
|
|
28
|
+
-->
|
|
29
|
+
|
|
30
|
+
## Alternatives
|
|
31
|
+
|
|
32
|
+
<!--
|
|
33
|
+
If you’ve considered any alternative solutions or workarounds, please list them here.
|
|
34
|
+
-->
|
|
35
|
+
|
|
36
|
+
## Additional Context
|
|
37
|
+
|
|
38
|
+
<!--
|
|
39
|
+
Include any other details or visuals that may help clarify the request.
|
|
40
|
+
-->
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "Bug Issue"
|
|
3
|
+
about: "Submit a bug report"
|
|
4
|
+
title: ""
|
|
5
|
+
labels: "bug"
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
<!--
|
|
12
|
+
Please provide a clear and concise description of the issue or feature request.
|
|
13
|
+
For a bug report, describe the bug. For a feature, describe the enhancement you would like to see.
|
|
14
|
+
-->
|
|
15
|
+
|
|
16
|
+
## Steps to Reproduce (for bugs)
|
|
17
|
+
|
|
18
|
+
<!--
|
|
19
|
+
1. Outline the exact steps to reproduce the problem.
|
|
20
|
+
2. Detail any environment or configuration changes that might be relevant.
|
|
21
|
+
3. Include any code snippets or console logs, if helpful.
|
|
22
|
+
-->
|
|
23
|
+
|
|
24
|
+
1. ...
|
|
25
|
+
2. ...
|
|
26
|
+
3. ...
|
|
27
|
+
|
|
28
|
+
## Expected Behavior (for bugs)
|
|
29
|
+
|
|
30
|
+
<!--
|
|
31
|
+
What should have happened?
|
|
32
|
+
-->
|
|
33
|
+
|
|
34
|
+
## Actual Behavior (for bugs)
|
|
35
|
+
|
|
36
|
+
<!--
|
|
37
|
+
What actually happened instead?
|
|
38
|
+
-->
|
|
39
|
+
|
|
40
|
+
## Proposed Solution or Feature Request
|
|
41
|
+
|
|
42
|
+
<!--
|
|
43
|
+
If you are requesting a feature or have a suggested fix/solution for the bug, please provide details here.
|
|
44
|
+
-->
|
|
45
|
+
|
|
46
|
+
## Additional Context
|
|
47
|
+
|
|
48
|
+
<!--
|
|
49
|
+
Add any other context, screenshots, videos, or additional information that may be helpful.
|
|
50
|
+
-->
|
|
51
|
+
|
|
52
|
+
## Environment
|
|
53
|
+
|
|
54
|
+
- **Package Version**:
|
|
55
|
+
- **Node.js Version**:
|
|
56
|
+
- **Browser (if applicable)**:
|
|
57
|
+
- **Operating System**:
|
|
58
|
+
- **Additional Details**:
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
<!-- Provide a short summary explaining the purpose of this pull request. -->
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Related Issue
|
|
7
|
+
|
|
8
|
+
<!-- If this pull request fixes or is related to an existing issue, link to it here. -->
|
|
9
|
+
<!-- For example: "Closes #123" or "Fixes #123" -->
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Type of Change
|
|
13
|
+
|
|
14
|
+
<!-- Mark with an x all the checkboxes that apply (like [x]). -->
|
|
15
|
+
|
|
16
|
+
- [ ] Bug fix
|
|
17
|
+
- [ ] New feature
|
|
18
|
+
- [ ] Refactoring (no functional changes, no API changes)
|
|
19
|
+
- [ ] Documentation update
|
|
20
|
+
- [ ] Other (please describe):
|
|
21
|
+
|
|
22
|
+
## Proposed Changes
|
|
23
|
+
|
|
24
|
+
<!--
|
|
25
|
+
Provide additional details regarding the changes made.
|
|
26
|
+
For example, list out key points you implemented or refactored.
|
|
27
|
+
-->
|
|
28
|
+
|
|
29
|
+
1. ...
|
|
30
|
+
2. ...
|
|
31
|
+
3. ...
|
|
32
|
+
|
|
33
|
+
## How Has This Been Tested?
|
|
34
|
+
|
|
35
|
+
<!--
|
|
36
|
+
Describe the tests you ran to ensure the code works as expected.
|
|
37
|
+
Include instructions so we can reproduce your tests.
|
|
38
|
+
-->
|
|
39
|
+
|
|
40
|
+
- [ ] Unit Tests
|
|
41
|
+
- [ ] Integration Tests
|
|
42
|
+
- [ ] Manual Testing
|
|
43
|
+
|
|
44
|
+
**Test Configuration**:
|
|
45
|
+
- Node.js Version:
|
|
46
|
+
- NPM/Yarn Version:
|
|
47
|
+
- Operating System:
|
|
48
|
+
|
|
49
|
+
## Checklist
|
|
50
|
+
|
|
51
|
+
- [ ] I have read the [contribution guidelines](../CONTRIBUTING.md).
|
|
52
|
+
- [ ] My code follows the style of this project.
|
|
53
|
+
- [ ] I have added tests to cover my changes.
|
|
54
|
+
- [ ] All new and existing tests passed.
|
|
55
|
+
- [ ] I have updated the documentation as needed (inline code comments / README / any other relevant documentation).
|
|
56
|
+
|
|
57
|
+
## Additional Comments
|
|
58
|
+
|
|
59
|
+
<!--
|
|
60
|
+
Add any other context or screenshots about the pull request here.
|
|
61
|
+
-->
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
# Contributing to @yourusername/shuffle-array
|
|
3
|
+
|
|
4
|
+
> Thank you for your interest in contributing! Your help is greatly appreciated.
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
|
|
8
|
+
- [How Can You Contribute?](#how-can-you-contribute)
|
|
9
|
+
- [Development Setup](#development-setup)
|
|
10
|
+
- [Committing Changes](#committing-changes)
|
|
11
|
+
|
|
12
|
+
## How Can You Contribute?
|
|
13
|
+
|
|
14
|
+
1. **Report Bugs**
|
|
15
|
+
- If you find any bugs, please open an issue in the repository. Please follow the [ISSUE_TEMPLATE.md](./.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md)
|
|
16
|
+
|
|
17
|
+
2. **Suggest Features**
|
|
18
|
+
- If you have an idea for a feature or improvement, feel free to open an issue describing your idea. Please follow the [FEATURE_REQUEST_TEMPLATE.md](./.github/ISSUE_TEMPLATE/FEATURE_REQUEST_TEMPLATE.md)
|
|
19
|
+
|
|
20
|
+
3. **Create Pull Requests**
|
|
21
|
+
- PRs for bug fixes, enhancements, or documentation updates are always welcome.
|
|
22
|
+
- Please ensure all tests pass and that the code is well-documented.
|
|
23
|
+
- Please follow the [PULL_REQUEST_TEMPLATE.md](./.github/PULL_REQUEST_TEMPLATE.md)
|
|
24
|
+
|
|
25
|
+
## Development Setup
|
|
26
|
+
|
|
27
|
+
1. **Clone the repository**:
|
|
28
|
+
```sh
|
|
29
|
+
git clone https://github.com/yourusername/shuffle-array.git
|
|
30
|
+
cd shuffle-array
|
|
31
|
+
```
|
|
32
|
+
2. **Install dependencies**:
|
|
33
|
+
```sh
|
|
34
|
+
npm install
|
|
35
|
+
```
|
|
36
|
+
3. **Build the package**:
|
|
37
|
+
```sh
|
|
38
|
+
npm run build
|
|
39
|
+
```
|
|
40
|
+
4. **Run tests**:
|
|
41
|
+
```sh
|
|
42
|
+
npm run tests
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Committing Changes
|
|
46
|
+
|
|
47
|
+
Please follow these guidelines for commit messages and pull requests:
|
|
48
|
+
- **Commit Message Format**: Commit messages should be descriptive, e.g., `feat: add new shuffle algorithm` following the [Conventional Commits Specification](https://www.conventionalcommits.org/en). It is easy to follow if you are using the [semantic-git-commit-cli](https://www.npmjs.com/package/semantic-git-commit-cli)
|
|
49
|
+
- **Pull Request**: If you open a Pull Request please follow the [PULL_REQUEST_TEMPLATE.md](./.github/PULL_REQUEST_TEMPLATE.md).
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2025-current <YOUR-NAME>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @yourusername/shuffle-array (Class 2 Example)
|
|
2
|
+
|
|
3
|
+
> A small library that takes an array as input and returns a new array that is shuffled.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Examples](#examples)
|
|
10
|
+
- [Contribution](#contribution)
|
|
11
|
+
- [Security](#security)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install via npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @yourusername/shuffle-array
|
|
20
|
+
```
|
|
21
|
+
Install via yarn:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @yourusername/shuffle-array
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
Basic Usage
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import shuffleArray from '@yourusername/shuffle-array';
|
|
33
|
+
|
|
34
|
+
const startArray = [1, 2, 3, 4, 5];
|
|
35
|
+
const newShuffledArray = shuffleArray(startArray);
|
|
36
|
+
|
|
37
|
+
console.log(startArray); // e.g., [1, 2, 3, 4, 5]
|
|
38
|
+
console.log(newShuffledArray); // e.g., [3, 1, 5, 2, 4]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Examples
|
|
42
|
+
|
|
43
|
+
Shuffle a list of user IDs:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import shuffleArray from '@yourusername/shuffle-array';
|
|
47
|
+
|
|
48
|
+
const userIds = ['u1', 'u2', 'u3', 'u4'];
|
|
49
|
+
const randomizedOrderOfUserIds = shuffleArray(userIds);
|
|
50
|
+
|
|
51
|
+
console.log(randomizedOrderOfUserIds); // e.g., ['u1', 'u3', 'u4', 'u2']
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use in a game for randomizing cards:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import shuffleArray from '@yourusername/shuffle-array';
|
|
58
|
+
|
|
59
|
+
const deck = ['Ace of Spades', 'Two of Hearts']; // some card deck
|
|
60
|
+
const shuffledDeck = shuffleArray(deck);
|
|
61
|
+
|
|
62
|
+
console.log(shuffledDeck); // e.g., ['Two of Hearts', 'Ace of Spades', ...]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Contribution
|
|
66
|
+
|
|
67
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.
|
|
68
|
+
|
|
69
|
+
## Security
|
|
70
|
+
|
|
71
|
+
Please refer to our [SECURITY.md](./SECURITY.md) for information about our security policies, how to report vulnerabilities, and our approach to handling security concerns.
|
|
72
|
+
|
|
73
|
+
**Important Note**: This library uses non-cryptographic randomness (`Math.random()`). Do not rely on it for security-critical functionality.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
This project is licensed under the [MIT License](./LICENSE.md).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
We only provide official security updates for the current major release (e.g., `1.x`). Older versions may not be actively maintained or patched for vulnerabilities.
|
|
4
|
+
|
|
5
|
+
## Supported Versions
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | --------- |
|
|
9
|
+
| 1.x | ✅ |
|
|
10
|
+
| 0.x | ❌ |
|
|
11
|
+
|
|
12
|
+
## Reporting a Vulnerability
|
|
13
|
+
|
|
14
|
+
We take security issues seriously and appreciate your efforts to responsibly disclose them. If you believe you have found a security vulnerability in this project, please follow these steps:
|
|
15
|
+
|
|
16
|
+
1. **Contact the Team**
|
|
17
|
+
Send an email to **[security@yourdomain.com](mailto:security@yourdomain.com)** with a clear description of the issue, the steps to reproduce it, and any potential impact it may have.
|
|
18
|
+
|
|
19
|
+
2. **Do Not Disclose Publicly**
|
|
20
|
+
Please do not file a public issue for a vulnerability, as it may put other users at risk. We ask that you keep any discovered vulnerabilities confidential until we have a fix in place.
|
|
21
|
+
|
|
22
|
+
3. **Confirmation**
|
|
23
|
+
You should receive an acknowledgment of your report within **72 hours**. If you do not hear back, feel free to follow up.
|
|
24
|
+
|
|
25
|
+
4. **Fix & Disclosure**
|
|
26
|
+
After we address the issue, we will release a fix as soon as possible. We will also publish a short advisory and acknowledge your contribution once the patch is made public.
|
|
27
|
+
|
|
28
|
+
## Scope
|
|
29
|
+
|
|
30
|
+
- Our project does not handle sensitive data like passwords or personal user information beyond normal usage.
|
|
31
|
+
- Please note that this library uses non-cryptographic randomness (e.g., `Math.random()`) and therefore is **not** intended for security-critical tasks.
|
|
32
|
+
|
|
33
|
+
## Resources
|
|
34
|
+
|
|
35
|
+
- [GitHub Security Documentation](https://docs.github.com/en/code-security)
|
|
36
|
+
- [Responsible Disclosure Guidelines](https://en.wikipedia.org/wiki/Responsible_disclosure)
|
|
37
|
+
|
|
38
|
+
Thank you for helping us keep this project secure!
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// jest.config.js
|
|
2
|
+
module.exports = {
|
|
3
|
+
testEnvironment: 'node', // sets the test environment to Node.js
|
|
4
|
+
moduleFileExtensions: ['js', 'json'], // recognize .js and .json files
|
|
5
|
+
testMatch: ['**/?(*.)+(spec).js'], // run files ending with .spec.js
|
|
6
|
+
// Uncomment the transform section if you're using ES6+ features that need Babel
|
|
7
|
+
// transform: {
|
|
8
|
+
// '^.+\\.jsx?$': 'babel-jest'
|
|
9
|
+
// },
|
|
10
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@itreg/shuffle-array",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A small library that takes an array as input and returns a new array that is shuffled.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"umd:main": "dist/index.umd.js",
|
|
7
|
+
"module": "dist/index.m.js",
|
|
8
|
+
"source": "src/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "microbundle",
|
|
11
|
+
"pretest": "npm run build",
|
|
12
|
+
"test": "npx jest --coverage"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/itregit/shuffle-array.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"array",
|
|
20
|
+
"shuffle",
|
|
21
|
+
"functional"
|
|
22
|
+
],
|
|
23
|
+
"author": "itreg",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/itregit/shuffle-array/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/itregit/shuffle-array#readme",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"jest": "^29.7.0",
|
|
31
|
+
"microbundle": "^0.15.1"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const shuffleArray = require('../dist/index');
|
|
2
|
+
|
|
3
|
+
describe('shuffleArray', () => {
|
|
4
|
+
test('returns a new array with the same elements as the input', () => {
|
|
5
|
+
const originalArray = [1, 2, 3, 4, 5];
|
|
6
|
+
const shuffledArray = shuffleArray(originalArray);
|
|
7
|
+
|
|
8
|
+
// Check that a new array is returned (not the same reference)
|
|
9
|
+
expect(shuffledArray).not.toBe(originalArray);
|
|
10
|
+
|
|
11
|
+
// Check that the array lengths are identical
|
|
12
|
+
expect(shuffledArray.length).toBe(originalArray.length);
|
|
13
|
+
|
|
14
|
+
// Check that both arrays contain the same elements, regardless of order
|
|
15
|
+
const sortedOriginal = [...originalArray].sort((a, b) => a - b);
|
|
16
|
+
const sortedShuffled = [...shuffledArray].sort((a, b) => a - b);
|
|
17
|
+
expect(sortedShuffled).toEqual(sortedOriginal);
|
|
18
|
+
});
|
|
19
|
+
});
|