@vpmedia/simplify 1.0.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/CHANGES.md ADDED
@@ -0,0 +1,8 @@
1
+ # Release notes
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## 1.0.0
7
+
8
+ - Initial release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Richard Davey, Photon Storm Ltd.
4
+ Copyright (c) 2022-present Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @vpmedia/simplify
2
+
3
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.0.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
4
+ [![Node.js CI](https://github.com/vpmedia/simplify/actions/workflows/node.js.yml/badge.svg)](https://github.com/vpmedia/simplify/actions/workflows/node.js.yml)
5
+
6
+ @vpmedia/simplify TBD
7
+
8
+ ## Getting started
9
+
10
+ $ npm install --save @vpmedia/simplify
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@vpmedia/simplify",
3
+ "version": "1.0.0",
4
+ "description": "@vpmedia/simplify",
5
+ "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/vpmedia/simplify#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/vpmedia/simplify/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/vpmedia/simplify.git"
14
+ },
15
+ "keywords": [
16
+ "utils"
17
+ ],
18
+ "main": "./src/index.js",
19
+ "types": "./types/index.d.ts",
20
+ "type": "module",
21
+ "devDependencies": {
22
+ "@babel/preset-env": "^7.23.2",
23
+ "@jest/globals": "^29.7.0",
24
+ "@types/jest": "^29.5.6",
25
+ "eslint": "^8.51.0",
26
+ "eslint-config-prettier": "^9.0.0",
27
+ "eslint-plugin-import": "^2.28.1",
28
+ "eslint-plugin-jest": "^27.4.2",
29
+ "eslint-plugin-jsdoc": "^46.8.2",
30
+ "eslint-plugin-prettier": "^5.0.1",
31
+ "husky": "^8.0.3",
32
+ "jest": "^29.7.0",
33
+ "jest-environment-jsdom": "^29.7.0",
34
+ "lint-staged": "^15.0.1",
35
+ "prettier": "^3.0.3",
36
+ "typescript": "^5.2.2"
37
+ },
38
+ "scripts": {
39
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
40
+ "lint": "eslint --fix \"**/*.{js,jsx}\"",
41
+ "typecheck": "tsc",
42
+ "format": "prettier --write \"**/*.{css,js,jsx,json,md}\"",
43
+ "prepare": "husky install",
44
+ "lint-staged": "lint-staged"
45
+ },
46
+ "browserslist": [
47
+ "> 1%",
48
+ "not dead",
49
+ "not op_mini all"
50
+ ],
51
+ "engines": {
52
+ "npm": ">=8.0.0",
53
+ "node": ">=18.0.0"
54
+ }
55
+ }
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // core
2
+ import { capitalize } from './util/capitalize.js';
3
+ import { getRandomInt } from './util/getRandomInt.js';
4
+ import { getURLParam } from './util/getURLParam.js';
5
+ import { sanitizeURLParam } from './util/sanitizeURLParam.js';
6
+ import { underscoreToCamelcase } from './util/underscoreToCamelCase.js';
7
+ // exports
8
+ export { capitalize, getRandomInt, getURLParam, sanitizeURLParam, underscoreToCamelcase };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Capitalize a string.
3
+ * @param {string} value - Ther input string.
4
+ * @returns {string} TBD.
5
+ */
6
+ export function capitalize(value) {
7
+ if (!value || value.length === 0) {
8
+ return value;
9
+ }
10
+ const normValue = value.toLowerCase();
11
+ return normValue.charAt(0).toUpperCase() + normValue.slice(1);
12
+ }
@@ -0,0 +1,6 @@
1
+ import { capitalize } from './capitalize.js';
2
+
3
+ test('Tests capitalize first letter', () => {
4
+ expect(capitalize('test')).toBe('Test');
5
+ expect(capitalize(null)).toBe(null);
6
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns random integer in range.
3
+ * @param {number} min - Min value.
4
+ * @param {number} max - Max value.
5
+ * @returns {number} Random integer in given range.
6
+ */
7
+ export function getRandomInt(min, max) {
8
+ return Math.floor(Math.random() * (max - min + 1)) + min;
9
+ }
@@ -0,0 +1,5 @@
1
+ import { getRandomInt } from './getRandomInt.js';
2
+
3
+ test('TBD', () => {
4
+ expect(getRandomInt(1, 1)).toBe(1);
5
+ });
@@ -0,0 +1,21 @@
1
+ import { sanitizeURLParam } from './sanitizeURLParam.js';
2
+
3
+ const urlSearchParams = new URLSearchParams(window.location.search);
4
+
5
+ /**
6
+ * TBD.
7
+ * @param {string} key - TBD.
8
+ * @param {*} defaultValue - TBD.
9
+ * @param {boolean} isSanitize - TBD.
10
+ * @returns {string} TBD.
11
+ */
12
+ export function getURLParam(key, defaultValue = null, isSanitize = true) {
13
+ const paramValue = urlSearchParams.get(key);
14
+ if (paramValue === null || paramValue === undefined) {
15
+ return defaultValue;
16
+ }
17
+ if (isSanitize) {
18
+ return sanitizeURLParam(paramValue);
19
+ }
20
+ return paramValue;
21
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sanitizes URL parameters allowing only alpha-numeric characters and dash.
3
+ * @param {string} input - The input string to be sanitized.
4
+ * @returns {string} The sanitized output string.
5
+ */
6
+ export function sanitizeURLParam(input) {
7
+ if (!input) {
8
+ return input;
9
+ }
10
+ return input.replace(/[^a-zA-Z0-9-_]/gi, '');
11
+ }
@@ -0,0 +1,6 @@
1
+ import { sanitizeURLParam } from './sanitizeURLParam.js';
2
+
3
+ test('Tests URL parameter sanitizer', () => {
4
+ expect(sanitizeURLParam('abc<>-123[]{}-()A_BC')).toBe('abc-123-A_BC');
5
+ expect(sanitizeURLParam(null)).toBe(null);
6
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Converts underscore case string to camel case.
3
+ * @param {string} value - The input string in underscore case.
4
+ * @returns {string} The output string in camel case.
5
+ */
6
+ export function underscoreToCamelcase(value) {
7
+ return value.replace(/(_\w)/g, function (m) {
8
+ return m[1].toUpperCase();
9
+ });
10
+ }
@@ -0,0 +1,7 @@
1
+ import { underscoreToCamelcase } from './underscoreToCamelCase.js';
2
+
3
+ test('TBD', () => {
4
+ expect(underscoreToCamelcase('test')).toBe('test');
5
+ expect(underscoreToCamelcase('test_variable')).toBe('testVariable');
6
+ expect(underscoreToCamelcase('test_variable_name')).toBe('testVariableName');
7
+ });
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ interface Window {}
3
+ }
4
+
5
+ export {};
@@ -0,0 +1,3 @@
1
+ export { capitalize };
2
+ import { capitalize } from './util/capitalize.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";2BAC2B,sBAAsB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Capitalize a string.
3
+ * @param {string} value - Ther input string.
4
+ * @returns {string} TBD.
5
+ */
6
+ export function capitalize(value: string): string;
7
+ //# sourceMappingURL=capitalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../../src/util/capitalize.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,kCAHW,MAAM,GACJ,MAAM,CAQlB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns random integer in range.
3
+ * @param {number} min - Min value.
4
+ * @param {number} max - Max value.
5
+ * @returns {number} Random integer in given range.
6
+ */
7
+ export function getRandomInt(min: number, max: number): number;
8
+ //# sourceMappingURL=getRandomInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRandomInt.d.ts","sourceRoot":"","sources":["../../src/util/getRandomInt.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,kCAJW,MAAM,OACN,MAAM,GACJ,MAAM,CAIlB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * TBD.
3
+ * @param {string} key - TBD.
4
+ * @param {*} defaultValue - TBD.
5
+ * @param {boolean} isSanitize - TBD.
6
+ * @returns {string} TBD.
7
+ */
8
+ export function getURLParam(key: string, defaultValue?: any, isSanitize?: boolean): string;
9
+ //# sourceMappingURL=getURLParam.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getURLParam.d.ts","sourceRoot":"","sources":["../../src/util/getURLParam.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,iCALW,MAAM,mCAEN,OAAO,GACL,MAAM,CAWlB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Sanitizes URL parameters allowing only alpha-numeric characters and dash.
3
+ * @param {string} input - The input string to be sanitized.
4
+ * @returns {string} The sanitized output string.
5
+ */
6
+ export function sanitizeURLParam(input: string): string;
7
+ //# sourceMappingURL=sanitizeURLParam.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeURLParam.d.ts","sourceRoot":"","sources":["../../src/util/sanitizeURLParam.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wCAHW,MAAM,GACJ,MAAM,CAOlB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts underscore case string to camel case.
3
+ * @param {string} value - The input string in underscore case.
4
+ * @returns {string} The output string in camel case.
5
+ */
6
+ export function underscoreToCamelcase(value: string): string;
7
+ //# sourceMappingURL=underscoreToCamelCase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"underscoreToCamelCase.d.ts","sourceRoot":"","sources":["../../src/util/underscoreToCamelCase.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,6CAHW,MAAM,GACJ,MAAM,CAMlB"}