@mtorre4580/is-deprecated 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Matias Daniel Torre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # deprecated
2
+
3
+ A utility library designed to notify about deprecated functions or methods within objects.
4
+
5
+ <img width="128" height="128" src="https://github.com/mtorre4580/deprecated/blob/main/deprecated.png?raw=true" />
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ npm i deprecated
11
+ ```
12
+
13
+ ## Parameters
14
+
15
+ - obj (Object|Function): The object or function to check for deprecation.
16
+
17
+ - config (Object): Configuration object with the following properties:
18
+ - method (String): The method name to be deprecated within the object.
19
+ - message (String): Custom deprecation message (default: 'This will be deprecated soon').
20
+ - logger (Object): Logger object for warning messages (default: console).
21
+ - sendMetrics (Function): Function to send metrics upon deprecation (default: empty function).
22
+
23
+ ## Usage
24
+
25
+ Function to notify about deprecation and wrap the function/method with deprecation warnings.
26
+
27
+ ### With Function
28
+
29
+ ```js
30
+ import deprecated from "deprecated";
31
+
32
+ // Function to add the deprecated helper
33
+ const myFunction = (arg1, arg2) => {};
34
+
35
+ // Basic config
36
+ const config = {
37
+ message:
38
+ "myFunction will be removed in the next release, please replace with this https://www.npmjs.com",
39
+ };
40
+
41
+ // Create the wrapper to use
42
+ const deprecatedMyFunction = deprecated(myFunction, config);
43
+
44
+ // Call the wrapper function to see the warning
45
+ deprecatedMyFunction('', {});
46
+ ```
47
+
48
+ ### With Function in Object
49
+
50
+ ```js
51
+ import deprecated from "deprecated";
52
+
53
+ // Object to apply the deprecated method
54
+ const API = {
55
+ timeout: 5000,
56
+ getUsers() {
57
+ return new Promise((resolve, reject) => {
58
+ setTimeOut(() => {
59
+ resolve([
60
+ { id: 2, name: "Matias" },
61
+ { id: 3, name: "Belen" },
62
+ ]);
63
+ }, 1000);
64
+ });
65
+ },
66
+ getUsersV2() {},
67
+ };
68
+
69
+ // Basic config
70
+ const config = {
71
+ message: "getUsers is deprecated in the next release, please with getUsersV2",
72
+ method: "getUsers",
73
+ };
74
+
75
+ // Create the wrapper to use
76
+ const APIWithDeprecated = deprecated(API, config);
77
+
78
+ // Call the wrapper function to see the warning
79
+ const users = await APIWithDeprecated.getUsers();
80
+ ```
81
+
82
+ ## Best Practices
83
+
84
+ - To building time use the jsdoc decorator [@deprecated](https://jsdoc.app/tags-deprecated) in the code
85
+ - To runtime use the function from this lib `deprecated` to notify in the console
86
+ - The sendMetrics function allows to get more insight what app is using the deprecated method to notify the team
87
+ - You can use any environment variable to apply the wrapper or not, if you only need to run in development or staging
@@ -0,0 +1,28 @@
1
+ var f = (e, r) => () => (r || e((r = { exports: {} }).exports, r), r.exports);
2
+ var h = f((w, c) => {
3
+ function u(e) {
4
+ return typeof e == "function";
5
+ }
6
+ function a(e, r) {
7
+ const {
8
+ method: n = null,
9
+ message: t = "This will be deprecated soon",
10
+ logger: o = console,
11
+ sendMetrics: i = () => {
12
+ }
13
+ } = r || {};
14
+ if (e == null)
15
+ throw new Error("The param obj is required");
16
+ if (u(e))
17
+ return o.warn(t), i(), (...s) => e(...s);
18
+ if (!u(e[n]))
19
+ throw new Error("The object not have the method defined");
20
+ return new Proxy(e, {
21
+ get(s, d) {
22
+ return d === n && (o.warn(t), i()), Reflect.get(...arguments);
23
+ }
24
+ });
25
+ }
26
+ c.exports = a;
27
+ });
28
+ export default h();
@@ -0,0 +1 @@
1
+ (function(n){typeof define=="function"&&define.amd?define(n):n()})(function(){"use strict";function n(e){return typeof e=="function"}function f(e,d){const{method:t=null,message:r="This will be deprecated soon",logger:i=console,sendMetrics:o=()=>{}}=d||{};if(e==null)throw new Error("The param obj is required");if(n(e))return i.warn(r),o(),(...u)=>e(...u);if(!n(e[t]))throw new Error("The object not have the method defined");return new Proxy(e,{get(u,c){return c===t&&(i.warn(r),o()),Reflect.get(...arguments)}})}module.exports=f});
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@mtorre4580/is-deprecated",
3
+ "version": "0.0.1",
4
+ "description": "Library to deprecated properties and methods in objects or functions",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mtorre4580/deprecated"
9
+ },
10
+ "homepage": "https://github.com/mtorre4580/deprecated/blob/main/README.md",
11
+ "bugs": {
12
+ "url": "https://github.com/mtorre4580/deprecated/issues"
13
+ },
14
+ "keywords": [
15
+ "deprecated",
16
+ "deprecated",
17
+ "javascript",
18
+ "nodejs"
19
+ ],
20
+ "author": "mtorre4580",
21
+ "files":["dist"],
22
+ "main":"./dist/deprecated.umd.js",
23
+ "module":"./dist/deprecated.es.js",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/deprecated.es.js",
27
+ "require": "./dist/deprecated.umd.js"
28
+ }
29
+ },
30
+ "scripts": {
31
+ "prepare": "husky install",
32
+ "dev": "vite",
33
+ "build": "vite build",
34
+ "preview": "vite preview",
35
+ "lint": "eslint '**/*.js'",
36
+ "lint:fix": "eslint '**/*.js' --fix",
37
+ "test": "jest --config jest.config.js",
38
+ "test:coverage": "jest --config jest.config.js --coverage",
39
+ "test:ci": "node --expose-gc ./node_modules/.bin/jest --ci --bail --runInBand --logHeapUsage --coverage",
40
+ "update-changelog": "git fetch && auto-changelog",
41
+ "audit": "yarn audit --groups 'dependencies devDependencies'"
42
+ },
43
+ "devDependencies": {
44
+ "@commitlint/cli": "^18.4.3",
45
+ "@commitlint/config-conventional": "^18.4.3",
46
+ "@types/jest": "^29.5.11",
47
+ "@types/node": "^20.10.4",
48
+ "auto-changelog": "^2.4.0",
49
+ "eslint": "^8.56.0",
50
+ "eslint-config-airbnb-base": "^15.0.0",
51
+ "eslint-plugin-import": "^2.29.1",
52
+ "husky": "^8.0.3",
53
+ "jest": "^29.7.0",
54
+ "vite": "^5.0.10"
55
+ },
56
+ "auto-changelog": {
57
+ "output": "CHANGELOG.md",
58
+ "template": "update-changelog.hbs",
59
+ "unreleased": false,
60
+ "commitLimit": false,
61
+ "startingVersion": "0.0.1",
62
+ "sortCommits": "date-desc",
63
+ "hideEmptyReleases": true
64
+ },
65
+ "engines": {
66
+ "node": ">=16"
67
+ }
68
+ }