-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.DS_Store | ||
node_modules | ||
dist | ||
index.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
{"version":"0.1.0","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","files":["dist","src"],"engines":{"node":">=10"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"name":"typescript","author":"Rajesh Rathore","module":"dist/typescript.esm.js","size-limit":[{"path":"dist/typescript.cjs.production.min.js","limit":"10 KB"},{"path":"dist/typescript.esm.js","limit":"10 KB"}],"devDependencies":{"@size-limit/preset-small-lib":"^8.2.6","husky":"^8.0.3","size-limit":"^8.2.6","tsdx":"^0.14.1","tslib":"^2.6.0","typescript":"^3.9.10"}} | ||
{ | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
}, | ||
"name": "typescript", | ||
"author": "Rajesh Rathore", | ||
"module": "dist/typescript.esm.js", | ||
"size-limit": [ | ||
{ | ||
"path": "dist/typescript.cjs.production.min.js", | ||
"limit": "10 KB" | ||
}, | ||
{ | ||
"path": "dist/typescript.esm.js", | ||
"limit": "10 KB" | ||
} | ||
], | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^8.2.6", | ||
"husky": "^8.0.3", | ||
"size-limit": "^8.2.6", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.6.0", | ||
"typescript": "^3.9.10" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function deprecated(target: any, key: string, descriptor: PropertyDescriptor) { | ||
Check failure on line 1 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
Check failure on line 1 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 14.x and ubuntu-latest
|
||
const originalDef = descriptor.value; | ||
Check failure on line 2 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
console.log(target) | ||
Check failure on line 3 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
descriptor.value = function (...args: any[]) { | ||
Check failure on line 4 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
console.log(`Warning: ${key}() is deprecated. Use other methods instead.`); | ||
Check failure on line 5 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
return originalDef.apply(this, args); | ||
Check failure on line 6 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
}; | ||
Check failure on line 7 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
return descriptor; | ||
Check failure on line 8 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
} | ||
Check failure on line 9 in src/Decorators/deprecated-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function enumerable(isEnumerable: boolean) { | ||
return (target: any, key: string, descriptor: PropertyDescriptor) => { | ||
Check failure on line 2 in src/Decorators/enumerable-decorator.ts GitHub Actions / Build, lint, and test on Node 12.x and ubuntu-latest
|
||
console.log(target,key); | ||
descriptor.enumerable = isEnumerable; | ||
console.log("The enumerable property of this member is set to: " + descriptor.enumerable); | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function frozen(target: Function) { | ||
Object.freeze(target); | ||
Object.freeze(target.prototype); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function required(target: any, key: string) { | ||
let currentValue = target[key]; | ||
|
||
Object.defineProperty(target, key, { | ||
set: (newValue: string) => { | ||
if (!newValue) { | ||
throw new Error(`${key} is required.`); | ||
} | ||
currentValue = newValue; | ||
}, | ||
get: () => currentValue, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const Rajesh='Rajesh' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,48 @@ | ||
export const sum = (a: number, b: number) => { | ||
if ('development' === process.env.NODE_ENV) { | ||
console.log('boop'); | ||
import { deprecated } from "./Decorators/deprecated-decorator"; | ||
import { enumerable } from "./Decorators/enumerable-decorator"; | ||
import { frozen } from "./Decorators/frozen.decorator"; | ||
import { required } from "./Decorators/required-decorator"; | ||
|
||
@frozen | ||
class User { | ||
private static userType: string = "Generic"; | ||
|
||
@required | ||
private _email: string; | ||
|
||
@required | ||
public username: string; | ||
|
||
public addressLine1: string = ""; | ||
public addressLine2: string = ""; | ||
public country: string = ""; | ||
|
||
constructor(username: string, email: string) { | ||
this.username = username; | ||
this._email = email; | ||
} | ||
return a + b; | ||
}; | ||
|
||
@enumerable(false) | ||
get userType() { | ||
return User.userType; | ||
} | ||
|
||
get email() { | ||
return this._email; | ||
} | ||
|
||
set email(newEmail: string) { | ||
this._email = newEmail; | ||
} | ||
|
||
@deprecated | ||
address(): any { | ||
return `${this.addressLine1}\n${this.addressLine2}\n${this.country}`; | ||
} | ||
} | ||
|
||
const p = new User("uut", "example@example.com"); | ||
p.addressLine1 = "1, New Avenue"; | ||
p.addressLine2 = "Bahcelievler, Istanbul"; | ||
p.address(); | ||
console.log(JSON.stringify(p)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
import { sum } from '../src'; | ||
|
||
describe('blah', () => { | ||
it('works', () => { | ||
expect(sum(1, 1)).toEqual(2); | ||
}); | ||
}); |