Skip to content

Commit

Permalink
feat(npm): add typescript examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tduyng committed Apr 13, 2023
1 parent 7871639 commit 04ceed2
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logger from '../../lib/esm/index.js'
import loggerCjs from '../../lib/cjs/index.cjs'
import loggerNpm from '@ekino/logger'
import loggerNpmTest from 'td-logger'

// ESM
logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('namespace:*')
logger.setLevel('info')

const log = logger.createLogger('namespace:subNamespace')

log.warn('example of esm', { someData: 'someValue of esm' })



// CJS
loggerCjs.setOutput(loggerCjs.outputs.pretty)
loggerCjs.setNamespaces('namespace:*')
loggerCjs.setLevel('info')

const logCjs = loggerCjs.createLogger('namespace:subNamespace')

logCjs.warn('example of cjs', { someData: 'someValue of common.js' })

// NPM @ekino/logger
loggerNpm.setOutput(loggerNpm.outputs.pretty)
loggerNpm.setNamespaces('namespace:*')
loggerNpm.setLevel('info')

const logNpm = loggerNpm.createLogger('namespace:subNamespace')

logNpm.warn('example of logger npm', { someData: 'someValue of logger npm' })

// NPM Test
loggerNpmTest.setOutput(loggerNpmTest.outputs.pretty)
loggerNpmTest.setNamespaces('namespace:*')
loggerNpmTest.setLevel('info')

const logNpmTest = loggerNpmTest.createLogger('namespace:subNamespace')

logNpmTest.warn('example of logger npm test', { someData: 'someValue of logger npm test' })
109 changes: 109 additions & 0 deletions examples/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "typescript-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "5.0.4"
},
"dependencies": {
"@ekino/logger": "2.1.1",
"td-logger": "3.0.0-rc"
}
}
25 changes: 25 additions & 0 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"incremental": true,
"noImplicitAny": true,
"allowJs": true,
"target": "esnext",
"lib": ["esnext","dom"],
"module": "nodenext",
"moduleResolution": "nodenext",
"alwaysStrict": true,
"skipLibCheck": true,
"noUnusedParameters": false,
"noUnusedLocals": false,
"strictNullChecks": true,
"noUncheckedIndexedAccess": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "lib"
},
"include": ["**/*.ts"],
}

0 comments on commit 04ceed2

Please sign in to comment.