@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 +8 -0
- package/LICENSE +21 -0
- package/README.md +10 -0
- package/package.json +55 -0
- package/src/index.js +8 -0
- package/src/util/capitalize.js +12 -0
- package/src/util/capitalize.test.js +6 -0
- package/src/util/getRandomInt.js +9 -0
- package/src/util/getRandomInt.test.js +5 -0
- package/src/util/getURLParam.js +21 -0
- package/src/util/sanitizeURLParam.js +11 -0
- package/src/util/sanitizeURLParam.test.js +6 -0
- package/src/util/underscoreToCamelCase.js +10 -0
- package/src/util/underscoreToCamelCase.test.js +7 -0
- package/typedefs/global.d.ts +5 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
- package/types/util/capitalize.d.ts +7 -0
- package/types/util/capitalize.d.ts.map +1 -0
- package/types/util/getRandomInt.d.ts +8 -0
- package/types/util/getRandomInt.d.ts.map +1 -0
- package/types/util/getURLParam.d.ts +9 -0
- package/types/util/getURLParam.d.ts.map +1 -0
- package/types/util/sanitizeURLParam.d.ts +7 -0
- package/types/util/sanitizeURLParam.d.ts.map +1 -0
- package/types/util/underscoreToCamelCase.d.ts +7 -0
- package/types/util/underscoreToCamelCase.d.ts.map +1 -0
package/CHANGES.md
ADDED
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
|
+
[](https://badge.fury.io/js/@vpmedia%2Fsimplify)
|
|
4
|
+
[](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,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,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,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
|
+
});
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";2BAC2B,sBAAsB"}
|
|
@@ -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"}
|