feat: initial project scaffold (randomString also)

This commit is contained in:
2023-11-10 23:20:30 +01:00
parent c3ca880060
commit 160ca41504
19 changed files with 3638 additions and 10201 deletions

View File

@@ -11,7 +11,6 @@
],
"rules": {
"no-console": 1,
"semi-style": ["error", "last"],
"semi": [2, "always"]
"semi-style": ["error", "last"]
}
}

12
.github/FUNDING.yml vendored
View File

@@ -1,12 +0,0 @@
# These are supported funding model platforms
github: [el3um4s]
patreon: el3um4s
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ["https://www.paypal.me/el3um4s"]

19
.github/workflows/jest.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Jest
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: yarn
- name: Build Typescript files
run: yarn build
- name: Run Jest
run: yarn test

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

7
.idea/discord.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View File

@@ -0,0 +1,17 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="50" name="TypeScript" />
</Languages>
</inspection_tool>
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JSUnusedAssignment" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/util-utils.iml" filepath="$PROJECT_DIR$/.idea/util-utils.iml" />
</modules>
</component>
</project>

9
.idea/util-utils.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

107
README.md
View File

@@ -1,106 +1,3 @@
# Typescript NPM Package Starter
My template for creating npm packages using typescript.
# util utils
- TS to JS
- Testing via Jest, includes coverage
- ESLint
- Ignore files to ensure minimal code is stored/shipped
NPM link: [@el3um4s/typescript-npm-package-starter](https://www.npmjs.com/package/@el3um4s/typescript-npm-package-starter)
### Getting Started
To create a new project based on this template using degit:
```bash
npx degit el3um4s/typescript-npm-package-starter
```
Then install the dependencies with
```bash
npm install
```
Now update the name field in package.json with your desired package name. Then update the homepage field in package.json. And finally add your code.
### Build the package
Run
```bash
npm run build
```
### Test the package
You can test the code with [Jest](https://jestjs.io/)
```bash
npm test
```
You can find the test coverage in `coverage/lcov-report/index.html`.
### Check dependencies
You can check and upgrade dependencies to the latest versions, ignoring specified versions. with [npm-check-updates](https://www.npmjs.com/package/npm-check-updates):
```bash
npm run check-updates
```
You can also use `npm run check-updates:minor` to update only patch and minor.
Instead `npm run check-updates:patch` only updates patch.
### Publish
First commit the changes to GitHub. Then login to your [NPM](https://www.npmjs.com) account (If you dont have an account you can do so on [https://www.npmjs.com/signup](https://www.npmjs.com/signup))
```bash
npm login
```
Then run publish:
```bash
npm publish
```
If you're using a scoped name use:
```bash
npm publish --access public
```
### Bumping a new version
To update the package use:
```bash
npm version patch
```
and then
```bash
npm publish
```
### Install and use the package
To use the package in a project:
```bash
npm i @el3um4s/typescript-npm-package-starter
```
and then in a file:
```ts
import { ciao } from "@el3um4s/typescript-npm-package-starter";
const b = ciao("mondo");
console.log(b); // Ciao Mondo
```
Zero-dependency everyday utility library for lazy Javascript developers

View File

@@ -3,7 +3,6 @@
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"collectCoverageFrom": ["src/**/*.{ts,tsx}"],
"collectCoverage":true
"moduleFileExtensions": ["ts", "js"],
"testEnvironment": "node"
}

10037
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,51 +1,32 @@
{
"name": "@el3um4s/typescript-npm-package-starter",
"version": "1.0.5",
"description": "Typescript NPM Package Starter",
"name": "util-utils",
"version": "1.0.0",
"description": "Zero-dependency everyday utility library for lazy Javascript developers",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint . --ext .ts",
"test": "jest --config jestconfig.json",
"test": "jest --runInBand --config jestconfig.json",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
"version": "git add -A src",
"postversion": "git push && git push --tags",
"check-updates": "npx npm-check-updates",
"check-updates:minor": "npx npm-check-updates --target minor",
"check-updates:patch": "npx npm-check-updates --target patch"
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/el3um4s/typescript-npm-package-starter.git"
"url": "git+https://github.com/SrIzan10/util-utils.git"
},
"files": [
"lib/**/*"
],
"keywords": [
"typescript",
"npm",
"template",
"ts"
"utils"
],
"author": "Samuele C. De Tomasi",
"author": "Sr Izan",
"license": "MIT",
"funding": [
{
"type": "patreon",
"url": "https://www.patreon.com/el3um4s"
},
{
"type": "individual",
"url": "https://www.paypal.me/el3um4s"
}
],
"bugs": {
"url": "https://github.com/el3um4s/typescript-npm-package-starter/issues"
},
"homepage": "https://github.com/el3um4s/typescript-npm-package-starter#readme",
"homepage": "https://github.com/SrIzan10/util-utils#readme",
"devDependencies": {
"@types/jest": "^29.4.0",
"@types/node": "^18.13.0",

View File

@@ -1,8 +0,0 @@
import { myCustomFunction, ciao } from '../index';
test('ciao', () => {
expect(ciao('Mondo')).toBe('Ciao Mondo');
});
test("myCustomFunction", () => {
expect(myCustomFunction('Mario')).toBe('Hello Mario');
});

View File

@@ -0,0 +1,13 @@
import { randomString } from '../index'
describe('randomString', () => {
it('should return a random string with the length of 10', () => {
const result = randomString(10)
expect(result).toHaveLength(10)
})
it('should return a random string with the length of 20 and a custom charset', () => {
const result = randomString(20, 'abc')
expect(result).toHaveLength(20)
expect(result).toMatch(/[abc]{20}/)
})
})

View File

@@ -1,6 +1 @@
const myCustomFunction = (name: string):string => `Hello ${name}`;
function ciao(name: string): string {
return `Ciao ${name}`;
}
export { myCustomFunction, ciao};
export { randomString } from './utils/randomString';

View File

@@ -0,0 +1,8 @@
export function randomString(length: number, dictionary?: string) {
const chars = (dictionary || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz').split('');
let str = '';
for (let i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}

3522
yarn.lock Normal file

File diff suppressed because it is too large Load Diff