Idris Brhane

Idris Brhane

1605059460

Local Cache for Deno / Typescript

Local Cache

Local runtime caching for deno / typescript with ttl availability

Usage

import { Cache } from "https://deno.land/x/local_cache";

interface Person {
    firstName: string,
    lastName: string
}

// Create a new cache with a global ttl of 30 seconds
const cache: Cache<string, Person> = new Cache<string, Person>(30000);

// Listen for 'ttl' events
cache.on('ttl', (key: string, person: Person, ttl: number) => {
    console.log(`'${person.firstName} ${person.lastName}' with ID '${key}' expired after ${ttl / 1000} seconds`); 
});

// Listen for 'add' events
cache.on('add', (key: string, person: Person, ttl?: number) => {
    console.log(`Cached '${person.firstName} ${person.lastName}' with ID '${key}' [Expires after ${(ttl || 0) / 1000} seconds]`)
})

// add a new person with its own ttl of 5 seconds (overrides global ttl)
cache.add('someUniqueID', {
    firstName: 'John',
    lastName: 'Doe'
}, 5000);

API

<Cache<K, V>>.add(key: K, value: V) => void;
<Cache<K, V>>.set(key: K, value: V) => void;
<Cache<K, V>>.get(key: K) => V;
<Cache<K, V>>.has(key: K) => boolean;
<Cache<K, V>>.delete(key: K) => void;
<Cache<K, V>>.clear() => void;
<Cache<K, V>>.empty() => boolean;
<Cache<K, V>>.clone() => Cache<K, V>;
Other methods not stated here for space sake

Events

<Cache<K, V>>.on('ttl', (key: K, value: V, ttl: number) => void);
<Cache<K, V>>.on('add', (key: K, value: V, ttl?: number) => void);
<Cache<K, V>>.on('set', (key: K, value: V, ttl?: number) => void);
<Cache<K, V>>.on('delete', (key: K, value: V) => void);
<Cache<K, V>>.on('claer', (map: Map<V>) => void);

Maintainer

- Somber (GitHub)

Download Details:

Author: SomberTM

Source Code: https://github.com/SomberTM/local_cache

#deno #node #nodejs #javascript

What is GEEK

Buddha Community

Local Cache for Deno / Typescript

The Definitive Guide to TypeScript & Possibly The Best TypeScript Book

TypeScript Deep Dive

I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack Overflow / DefinitelyTyped and general engagement with the TypeScript community. You can follow for updates and don't forget to β˜… on GitHub 🌹

Reviews

  • Thanks for the wonderful book. Learned a lot from it. (link)
  • Its probably the Best TypeScript book out there. Good Job (link)
  • Love how precise and clear the examples and explanations are! (link)
  • For the low, low price of free, you get pages of pure awesomeness. Chock full of source code examples and clear, concise explanations, TypeScript Deep Dive will help you learn TypeScript development. (link)
  • Just a big thank you! Best TypeScript 2 detailed explanation! (link)
  • This gitbook got my project going pronto. Fluent easy read 5 stars. (link)
  • I recommend the online #typescript book by @basarat you'll love it.(link)
  • I've always found this by @basarat really helpful. (link)
  • We must highlight TypeScript Deep Dive, an open source book.(link)
  • Great online resource for learning. (link)
  • Thank you for putting this book together, and for all your hard work within the TypeScript community. (link)
  • TypeScript Deep Dive is one of the best technical texts I've read in a while. (link)
  • Thanks @basarat for the TypeScript Deep Dive Book. Help me a lot with my first TypeScript project. (link)
  • Thanks to @basarat for this great #typescript learning resource. (link)
  • Guyz excellent book on Typescript(@typescriptlang) by @basarat (link)
  • Leaning on the legendary @basarat's "TypeScript Deep Dive" book heavily at the moment (link)
  • numTimesPointedPeopleToBasaratsTypeScriptBook++; (link)
  • A book not only for typescript, a good one for deeper JavaScript knowledge as well. link
  • In my new job, we're using @typescriptlang, which I am new to. This is insanely helpful huge thanks, @basarat! link
  • Thank you for writing TypeScript Deep Dive. I have learned so much. link
  • Loving @basarat's @typescriptlang online book basarat.gitbooks.io/typescript/# loaded with great recipes! link
  • Microsoft doc is great already, but if want to "dig deeper" into TypeScript I find this book of great value link
  • Thanks, this is a great book πŸ€“πŸ€“ link
  • Deep dive to typescript is awesome in so many levels. i find it very insightful. Thanks link
  • @basarat's intro to @typescriptlang is still one of the best going (if not THE best) link
  •  
  • This is sweet! So many #typescript goodies! link

Get Started

If you are here to read the book online get started.

Translations

Book is completely free so you can copy paste whatever you want without requiring permission. If you have a translation you want me to link here. Send a PR.

Other Options

You can also download one of the Epub, Mobi, or PDF formats from the actions tab by clicking on the latest build run. You will find the files in the artifacts section.

Special Thanks

All the amazing contributors 🌹

Share

Share URL: https://basarat.gitbook.io/typescript/

Author: Basarat
Source Code: https://github.com/basarat/typescript-book/ 
License: View license

#typescript #opensource 

Localization - Laravel Localization Example

In this example i will show you localization - laravel localization example.

Laravel’s localization features provide a convenient way to retrieve text in different languages, allowing you to easily support multiple languages within your application. So here i will show you how to create localization or laravel dynamic language.

Read More : Localization - Laravel Localization Example

https://websolutionstuff.com/post/localization-laravel-localization-example


Read Also : How To Integrate Paypal Payment Gateway In Laravel

https://websolutionstuff.com/post/how-to-integrate-paypal-payment-gateway-in-laravel

#localization - laravel localization example #localization tutorial #localization #laravel multi languag #laravel documentation #laravel localization

Rusty  Shanahan

Rusty Shanahan

1596666360

TypeScriptβ€Šβ€”β€ŠCompilation & the TypeScript Compiler

TypeScript provides a command-line utility tsc that compiles (transpiles) TypeScript files (_.ts_) into JavaScript. However, the tsc compiler (short for TypeScript compiler) needs a JSON configuration file to look for TypeScript files in the project and generate valid output files at a correct location.

When you run tsc command in a directory, TypeScript compiler looks for the tsconfig.json file in the current directory and if it doesn’t find one, then it keeps looking up the directory tree until it finds one. The directory where the tsconfig.json is located is considered as the root of the project.

You can manually provide a path to the tsconfig.json file using --project or -p command-line flag. This file doesn’t need to have the tsconfig.json filename if you are using this flag with the exact file path. However, you can also provide the directory path that contains the tsconfig.json file.

$ tsc -p /proj/x/tsconfig.dev.json

If the TypeScript compiler fails to locate this configuration file, you would get an error. But you can provide settings enlisted in this file through the equivalent command-line options which we will cover in the next lesson.

Structure of tsconfig.json

So what does this file contain and what exactly it controls?

{
  "files": [
    "src/lib/person.ts",
    "src/lib/student.ts",
    "src/main.ts"
  ],
  "compilerOptions": {
    "target": "ES6",
    "module": "CommonJS",
    "outDir": "./dist/development"
  }
}

The tsconfig.json file is a standard JSON file, however, it supports JSON5 specifications, so you can use comments, single quotes, and more. It contains some root-level options and some compiler options. The root-level options are options that are outside of the compilerOptions object, so in the above example, files is a root-level option.

The root-level options control how the project is presented to the TypeScript compiler, such as which TypeScript files to consider for the compilation. The compiler options contain settings for the TypeScript compiler such as where to output the compiled JavaScript files in the project directory.


ROOT-LEVEL OPTIONS

These options control how the project is presented to the TypeScript compiler for the compilation and static type analysis. These options must be kept outside compilerOptions object of the tsconfig.json file.

● files

The files array contains the location of the TypeScript files to consider for the compilation. These can be either relative paths or absolute paths on the disk. A relative path is located relative to the location of the tsconfig.json file (AKA root of the project).

/projects/sample/
β”œβ”€β”€ a.ts
β”œβ”€β”€ src/
|  β”œβ”€β”€ b.ts
|  β”œβ”€β”€ c.ts
|  β”œβ”€β”€ ignore.ts
|  └── lib/
|     β”œβ”€β”€ d.ts
|     └── e.ts
└── tsconfig.json

Let’s consider that we have the above directory structure in our project. As you can see, the TypeScript files (.ts) are located in multiple directories. We want to compile all the .ts files except the ignore.ts file. Hence we would provide relative paths of these files in the files options of tsconfig.json.

// tsconfig.json

{
    "files": [
        "a.ts",
        "src/b.ts",
        "./src/c.ts",
        "src/lib/d.ts",
        "./src/lib/e.ts"
    ]
}

You can also provide absolute paths of these files but relative paths are most recommended since they would be consistent on all the systems. All the relative paths are resolved against the path of tsconfig.json file in the project. You can optionally provide ./ or ../ prefix to locate the file.

Since we haven’t provided any compilerOptions values, all the default values for the compiler options are used which we will talk about in a bit. The TypeScript compiler compiles these files and outputs the JavaScript with .js extension by keeping the same file name as the individual input file.

The TypeScript compiler also preserves the original file path, hence the .js output file will be generated where the input file was in the directory structure. When you run the tsc command from the directory where your tsconfig.json file is located, you are going to see the result below.

/projects/sample/
β”œβ”€β”€ a.js
β”œβ”€β”€ a.ts
β”œβ”€β”€ src/
|  β”œβ”€β”€ b.js
|  β”œβ”€β”€ b.ts
|  β”œβ”€β”€ c.js
|  β”œβ”€β”€ c.ts
|  β”œβ”€β”€ ignore.ts
|  └── lib/
|     β”œβ”€β”€ d.js
|     β”œβ”€β”€ d.ts
|     β”œβ”€β”€ e.js
|     └── e.ts
└── tsconfig.json

As you can see, the TypeScript compiler compiled all the input TypeScript files listed inside files array of tsconfig.json. You can’t see the ignore.js file since ignore.ts file was not included in the files array.

The directory where the tsconfig.json file is located is considered as the root of the project, AKA the root directory. You can also include a file from outside this root directory, such by including "../x.ts" in the files array where x would be in the parent directory of the root directory. Since the TypeScript compiler preserves the input file path, it will generate x.js in the parent directory of the root directory.

● include & exclude

The files option is great when you have relatively few files to work with. But when your project is big and contains hundreds of source files located in a nested directory structure, then handpicking file paths is not practical.

To solve this issue, we can use include option. This option is just like files, however, we can optionally provide glob patterns to locate input files. The exclude options behave the same, except it removes the files from the compilation that may have been included by the include option.

// tsconfig.json

{
    "include": [
        "a.ts",
        "src/**/*.ts"
    ],
    "exclude": [
        "./**/*/ignore.ts"
    ]
}

In the above tsconfig.json, we have removed the files option and added include which adds a.ts file from the root directory and all the .ts file from the src directory. Since this would also include any ignore.ts from the src directory, we have provided the exclude option that excludes any ignore.ts file from the compilation if located inside the src directory.

When we run the tsc command now, results won’t be any different since the files considered for the compilation both in the previous example and this example are the same.

/projects/sample/
β”œβ”€β”€ a.js
β”œβ”€β”€ a.ts
β”œβ”€β”€ src/
|  β”œβ”€β”€ b.js
|  β”œβ”€β”€ b.ts
|  β”œβ”€β”€ c.js
|  β”œβ”€β”€ c.ts
|  β”œβ”€β”€ ignore.ts
|  └── lib/
|     β”œβ”€β”€ d.js
|     β”œβ”€β”€ d.ts
|     β”œβ”€β”€ e.js
|     └── e.ts
└── tsconfig.json

The TypeScript compiler automatically excludes files from the "node_modules""bower_components""jspm_packages" and "<outDir>" directories, where <outDir> is the value of outDir compiler-option provided by you. This prevents any .ts file from these directories getting included in the compilation process by accident.

#nodejs #typescript #deno #programming #javascript #deno

Mark Anderson

Mark Anderson

1616591309

Local Bitcoin Clone launch a trending business in crypto platform

The Blockchain App Factory offers a Local Bitcoin clone platform for its client with an impressive outcome that lures many users quickly. It allows the traders to buy and sell cryptocurrency for paying a particular party. This platform comes with peer-to-peer (P2P) with escrow for secure transactions, which helps in gaining trust and comfort with the feedback mechanism.

#local bitcoin clone script #buy & sell bitcoins with local currency #local bitcoin clone #best local bitcoin clone #local bitcoin exchange script #local bitcoin clone scripts

Mahesh Kale

1591947839

Deno - How to Compile & Run Typescript Code in Deno Runtime

Here in this video tutorial, you are going to learn how to make use of the Typescript code to run using the deno runtime. Check out the video in the youtube if you want on how to run typescript code in deno runtime.

You can check out the video below.

https://www.youtube.com/watch?v=T-ofshUKGc8

#deno #typescript #nodejs #node #tutorial #rust