- Notifications
You must be signed in to change notification settings - Fork 19
Using with Node
Alexandre Rogozine edited this page Mar 17, 2022
·
3 revisions
Ensure that you're using Current or LTS version of Node
Run npm init to setup the project.
Specify "type": "module".
Run npm install linq-to-typescript.
Create index.js with the following,
import{range}from"linq-to-typescript";constprimeNumbers=range(2,10000).select((i)=>[i,Math.floor(Math.sqrt(i))]).where(([i,iSq])=>range(2,iSq).all((j)=>i%j!==0)).select(([prime])=>prime).toArray();asyncfunctionasyncIterable(){forawait(constiofrange(0,10).selectAsync(async(x)=>x*2)){console.log(i);}}asyncIterable();console.log(primeNumbers);then run
node index.js
Ensure that you have TypeScript installed npm install typescript -g
Run tsc --init to create the tsconfig.json file
Configuring tsconfig.json
- Update the Typescript configuration file to target
ES2019. - Add the
ES2019to "lib" under "compilerOptions" - Set
"strict": trueunder "compilerOptions"
Add index.ts file with the following,
import{range}from"linq-to-typescript"constprimeNumbers=range(2,10000).select((i)=>[i,Math.floor(Math.sqrt(i))]).where(([i,iSq])=>range(2,iSq).all((j)=>i%j!==0)).select(([prime])=>prime).toArray()asyncfunctionasyncIterable(){forawait(constiofrange(0,10).selectAsync(async(x)=>x*2)){console.log(i)}}asyncIterable()console.log(primeNumbers)Run tsc to compile the index.ts to index.js
Run node index.js