<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pooja on Medium]]></title>
        <description><![CDATA[Stories by Pooja on Medium]]></description>
        <link>https://medium.com/@poojas.vc01?source=rss-8b1d82778453------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wYo141jnSSNEX4Fv</url>
            <title>Stories by Pooja on Medium</title>
            <link>https://medium.com/@poojas.vc01?source=rss-8b1d82778453------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:24:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@poojas.vc01/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Typescript- Arrays and functions]]></title>
            <link>https://medium.com/@poojas.vc01/typescript-arrays-and-functions-1cd1b864daa1?source=rss-8b1d82778453------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cd1b864daa1</guid>
            <dc:creator><![CDATA[Pooja]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 03:25:47 GMT</pubDate>
            <atom:updated>2024-02-23T03:26:16.561Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we’ll look at how to define and use arrays in our TypeScript code.</p><h3><strong>Working with Arrays</strong></h3><p>JavaScript arrays can contain data from any combination of types and have variable lengths.</p><p>Items can be added or removed without the needed to resize the array explicitly.</p><p>TypeScript doesn’t change the flexible array sizing, but we can use it to restrict the types of data that can be in an array.</p><p>For instance, we can write:</p><pre>let prices: number[] = [48, 23, 41];</pre><p>to restrict the prices array to only hold numbers.</p><p>number is the data type of each entry and [] indicates that it’s an array.</p><p>We can also use parentheses to indicate that an array can hold entries with different types of data.</p><p>For instance, we can write:</p><pre>let prices: (number | string)[] = [48, 23, &#39;88&#39;];</pre><p>So that prices can have strings in addition to numbers.</p><p>TypeScript will ensure that only operations that are allowed for number values are performed by the function.</p><h3>Equivalent Array Syntax</h3><p>We can specify the array data type with brackets.</p><p>For instance, we can write:</p><pre>let prices: Array&lt;number&gt; = [48, 23, 88];</pre><p>which is the same as:</p><pre>let prices: number[] = [48, 23, 88];</pre><h3>Array methods</h3><h4>1. concat()</h4><p>Joins arrays and returns an array with the joined arrays.</p><pre>const array1 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];<br>const array2 = [&#39;d&#39;, &#39;e&#39;, &#39;f&#39;];<br>const array3 = array1.concat(array2);<br><br>console.log(array3);<br>// Expected output: Array [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;]</pre><h4>2. copyWithin()</h4><p>Copies array elements within the array, to and from specified positions.</p><pre>const array1 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;];<br><br>// Copy to index 0 the element at index 3<br>console.log(array1.copyWithin(0, 3, 4));<br>// Expected output: Array [&quot;d&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;]<br><br>// Copy to index 1 all elements from index 3 to the end<br>console.log(array1.copyWithin(1, 3));<br>// Expected output: Array [&quot;d&quot;, &quot;d&quot;, &quot;e&quot;, &quot;d&quot;, &quot;e&quot;]</pre><h4>3. every()</h4><p>Checks if every element in an array passes a test.</p><pre>const isBelowThreshold = (currentValue) =&gt; currentValue &lt; 40;<br><br>const array1 = [1, 30, 39, 29, 10, 13];<br><br>console.log(array1.every(isBelowThreshold));<br>// Expected output: true<br></pre><h4>4. fill()</h4><p>Fill the elements in an array with a static value.</p><pre>const array1 = [1, 2, 3, 4];<br><br>// Fill with 0 from position 2 until position 4<br>console.log(array1.fill(0, 2, 4));<br>// Expected output: Array [1, 2, 0, 0]<br><br>// Fill with 5 from position 1<br>console.log(array1.fill(5, 1));<br>// Expected output: Array [1, 5, 5, 5]</pre><h4>5. filter()</h4><p>Creates a new array with every element in an array that passes a test.</p><pre>const words = [&#39;spray&#39;, &#39;elite&#39;, &#39;exuberant&#39;, &#39;destruction&#39;, &#39;present&#39;];<br><br>const result = words.filter((word) =&gt; word.length &gt; 6);<br><br>console.log(result);<br>// Expected output: Array [&quot;exuberant&quot;, &quot;destruction&quot;, &quot;present&quot;]</pre><h4>6. find()</h4><p>Returns the value of the first element in an array that passed a test.</p><pre>const array = [5, 12, 8, 130, 44];<br><br>const found = array.find((element) =&gt; element &gt; 10);<br><br>console.log(found);<br>// Expected output: 12</pre><h4>7. findIndex()</h4><p>Returns the index of the first element in an array that passed a test.</p><pre>const array1 = [5, 12, 8, 130, 44];<br><br>const isLargeNumber = (element) =&gt; element &gt; 13;<br><br>console.log(array1.findIndex(isLargeNumber));<br>// Expected output: 3</pre><h4>8. flat()</h4><p>creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.</p><pre>const arr1 = [0, 1, 2, [3, 4]];<br><br>console.log(arr1.flat());<br>// Expected output: Array [0, 1, 2, 3, 4]</pre><h4>9. flatMap()</h4><p>Returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level.</p><pre>const arr1 = [1, 2, 1];<br><br>const result = arr1.flatMap((num) =&gt; (num === 2 ? [2, 2] : 1));<br><br>console.log(result);<br>// Expected output: Array [1, 2, 2, 1]</pre><h4>10. forEach()</h4><p>Calls a function for each array element.</p><pre>const array1 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];<br><br>array1.forEach((element) =&gt; console.log(element));<br><br>// Expected output: &quot;a&quot;<br>// Expected output: &quot;b&quot;<br>// Expected output: &quot;c&quot;</pre><h4>11. includes()</h4><p>Check if an array contains the specified element.</p><pre>const pets = [&#39;cat&#39;, &#39;dog&#39;, &#39;bat&#39;];<br><br>console.log(pets.includes(&#39;cat&#39;));<br>// Expected output: true<br><br>console.log(pets.includes(&#39;at&#39;));<br>// Expected output: false</pre><h4>12. indexOf()</h4><p>Search the array for an element and returns its position.</p><pre>const beasts = [&#39;ant&#39;, &#39;bison&#39;, &#39;camel&#39;, &#39;duck&#39;, &#39;bison&#39;];<br><br>console.log(beasts.indexOf(&#39;bison&#39;));<br>// Expected output: 1</pre><h4>13. join()</h4><p>Joins all elements of an array into a string.</p><pre>const elements = [&#39;Fire&#39;, &#39;Air&#39;, &#39;Water&#39;];<br><br>console.log(elements.join());<br>// Expected output: &quot;Fire,Air,Water&quot;<br><br>console.log(elements.join(&#39;-&#39;));<br>// Expected output: &quot;Fire-Air-Water&quot;</pre><h4>14. keys()</h4><p>Returns an Array Iteration Object, containing the keys of the original array.</p><pre>const array1 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];<br>const iterator = array1.keys();<br><br>for (const key of iterator) {<br>  console.log(key);<br>}<br><br>// Expected output: 0<br>// Expected output: 1<br>// Expected output: 2</pre><h4>15. lastIndexOf()</h4><p>Search the array for an element, starting at the end, and returns its position.</p><pre>const animals = [&#39;Dodo&#39;, &#39;Tiger&#39;, &#39;Penguin&#39;, &#39;Dodo&#39;];<br><br>console.log(animals.lastIndexOf(&#39;Dodo&#39;));<br>// Expected output: 3</pre><h4>16. map()</h4><p>Creates a new array with the result of calling a function for each array element.</p><pre>const array = [1, 4, 9, 16];<br><br>// Pass a function to map<br>const map = array.map((x) =&gt; x * 2);<br><br>console.log(map);<br>// Expected output: Array [2, 8, 18, 32]</pre><h4>17. pop()</h4><p>Removes the last element of an array, and returns that element.</p><pre>const plants = [&#39;broccoli&#39;, &#39;cauliflower&#39;, &#39;cabbage&#39;, &#39;kale&#39;, &#39;tomato&#39;];<br><br>console.log(plants.pop());<br>// Expected output: &quot;tomato&quot;<br><br>console.log(plants);<br>// Expected output: Array [&quot;broccoli&quot;, &quot;cauliflower&quot;, &quot;cabbage&quot;, &quot;kale&quot;]</pre><h4>18. push()</h4><p>Adds new elements to the end of an array, and returns the new length.</p><pre>const animals = [&#39;pigs&#39;, &#39;goats&#39;, &#39;sheep&#39;];<br><br>const count = animals.push(&#39;cows&#39;);<br>console.log(count);<br>// Expected output: 4<br>console.log(animals);<br>// Expected output: Array [&quot;pigs&quot;, &quot;goats&quot;, &quot;sheep&quot;, &quot;cows&quot;]<br><br>animals.push(&#39;chickens&#39;, &#39;cats&#39;, &#39;dogs&#39;);<br>console.log(animals);<br>// Expected output: Array [&quot;pigs&quot;, &quot;goats&quot;, &quot;sheep&quot;, &quot;cows&quot;, &quot;chickens&quot;, &quot;cats&quot;, &quot;dogs&quot;]</pre><h4>19. reduce()</h4><p>Reduce the values of an array to a single value (going left-to-right).</p><pre>const array1 = [1, 2, 3, 4];<br><br>// 0 + 1 + 2 + 3 + 4<br>const initialValue = 0;<br>const sumWithInitial = array1.reduce(<br>  (accumulator, currentValue) =&gt; accumulator + currentValue,<br>  initialValue,<br>);<br><br>console.log(sumWithInitial);<br>// Expected output: 10</pre><h4>20. reverse()</h4><p>Reverses the order of the elements in an array.</p><pre>const array1 = [&#39;one&#39;, &#39;two&#39;, &#39;three&#39;];<br><br>const reversed = array1.reverse();<br>// Careful: reverse is destructive -- it changes the original array.<br>console.log(&#39;array1:&#39;, array1);<br>// Expected output: &quot;array1:&quot; Array [&quot;three&quot;, &quot;two&quot;, &quot;one&quot;]</pre><h4>21. shift()</h4><p>Removes the first element of an array, and returns that element.</p><pre>const array1 = [1, 2, 3];<br><br>const firstElement = array1.shift();<br><br>console.log(array1);<br>// Expected output: Array [2, 3]<br><br>console.log(firstElement);<br>// Expected output: 1</pre><h4>22. unshift()</h4><p>Adds new elements to the beginning of an array, and returns the new length.</p><pre>const array1 = [1, 2, 3];<br><br>console.log(array1.unshift(4, 5));<br>// Expected output: 5<br><br>console.log(array1);<br>// Expected output: Array [4, 5, 1, 2, 3]<br></pre><h4>23. slice()</h4><p>Selects a part of an array, and returns the new array.</p><pre>const animals = [&#39;ant&#39;, &#39;bison&#39;, &#39;camel&#39;, &#39;duck&#39;, &#39;elephant&#39;];<br><br>console.log(animals.slice(2));<br>// Expected output: Array [&quot;camel&quot;, &quot;duck&quot;, &quot;elephant&quot;]<br><br>console.log(animals.slice(2, 4));<br>// Expected output: Array [&quot;camel&quot;, &quot;duck&quot;]</pre><h4>24. some()</h4><p>Checks if any of the elements in an array pass a test.</p><pre>const array = [1, 2, 3, 4, 5];<br><br>// Checks whether an element is even<br>const even = (element) =&gt; element % 2 === 0;<br><br>console.log(array.some(even));<br>// Expected output: true</pre><h4>25. sort()</h4><p>Sorts the elements of an array.</p><pre>const months = [&#39;March&#39;, &#39;Jan&#39;, &#39;Feb&#39;, &#39;Dec&#39;];<br>months.sort();<br>console.log(months);<br>// Expected output: Array [&quot;Dec&quot;, &quot;Feb&quot;, &quot;Jan&quot;, &quot;March&quot;]<br><br>const array1 = [1, 30, 4, 21, 100000];<br>array1.sort();<br>console.log(array1);<br>// Expected output: Array [1, 100000, 21, 30, 4]</pre><h4>26. splice()</h4><p>Adds/Removes elements from an array.</p><pre>const months = [&#39;Jan&#39;, &#39;March&#39;, &#39;April&#39;, &#39;June&#39;];<br>months.splice(1, 0, &#39;Feb&#39;);<br>// Inserts at index 1<br>console.log(months);<br>// Expected output: Array [&quot;Jan&quot;, &quot;Feb&quot;, &quot;March&quot;, &quot;April&quot;, &quot;June&quot;]<br><br>months.splice(4, 1, &#39;May&#39;);<br>// Replaces 1 element at index 4<br>console.log(months);<br>// Expected output: Array [&quot;Jan&quot;, &quot;Feb&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;]</pre><h4>27. toString()</h4><p>Converts an array to a string, and returns the result.</p><pre>const array = [1, 2, &#39;a&#39;, &#39;1a&#39;];<br><br>console.log(array.toString());<br>// Expected output: &quot;1,2,a,1a&quot;</pre><h3>Tuple data type</h3><p>Tuple types define sets of arrays with a <strong>fixed length</strong>, and each index can contain a value of <strong>a different type</strong>.</p><p>For example, the tuple [string, number] defines the set of arrays containing <strong>exactly two values</strong>, where the first value is a string and the second value is a number.</p><pre>type Empty = [];<br>type One = [1];<br>type Two = [&quot;1&quot;, 2]; // types can be different!<br>type Three = [1, &quot;2&quot;, 1]; // tuples can contain duplicates</pre><h4><strong>Tuples &amp; Function Arguments</strong></h4><p>Now, if we combine tuples, <strong>named</strong> indices, and <strong>optional</strong> indices, here is the kind of tuples we can create:</p><pre>type UserTuple = [name: string, age?: number, ...addresses: string[]];<br><br>function createUser(...args: UserTuple) {}<br><br>//Function call like <br>createUser(&quot;Gabriel&quot;, 29, &quot;28 Central Ave&quot;, &quot;7500 Greenback Ln&quot;); </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cd1b864daa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Library]]></title>
            <link>https://medium.com/@poojas.vc01/angular-library-e4a4a1a1f76e?source=rss-8b1d82778453------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4a4a1a1f76e</guid>
            <dc:creator><![CDATA[Pooja]]></dc:creator>
            <pubDate>Thu, 02 Nov 2023 07:06:58 GMT</pubDate>
            <atom:updated>2023-11-02T07:06:58.399Z</atom:updated>
            <content:encoded><![CDATA[<p>An Angular library is an Angular <a href="https://angular.io/guide/glossary#project">project</a> that differs from an app in that it cannot run on its own. A library must be imported and used in an app. Angular added ability to create libraries with angular CLI.</p><p>Angular libraries are reusable code modules that can be shared across multiple Angular projects. They can contain components, services, directives, and other types of code, and can be easily imported and used in other projects as needed.</p><p>If you have developed functionality that is suitable for reuse, you can create your libraries. These libraries can be used locally in your workspace, or you can publish them as <a href="https://angular.io/guide/npm-packages">npm packages</a> to share with other projects or other Angular developers</p><h3>Why should we use library?</h3><p>It will enhance code reusability. We can import libraries in multiple Apps.</p><p>It will avoid various bad practices or architectural mistakes that can make it difficult to decouple and reuse code in the future</p><p>Some of the examples are:<br>1. ReactiveFormsModule from the <a href="http://twitter.com/angular/forms">@angular/forms</a> library is used to add reactive forms to an Angular app. We add this library package by using ng add <a href="http://twitter.com/angular/forms">@angular/forms</a> and then importing the ReactiveFormsModule from the <a href="http://twitter.com/angular/forms">@angular/forms</a>.</p><p>2. To turn an Angular App into a progressive application we add the service worker library. This turns our code into a Progressive Web App (PWA).</p><p>3. A very large and general-purpose library is the Angular Material. It is a library or a component that helps in constructing attractive, sophisticated, functional web app and reusable, and adaptable UI components.</p><p>And many more.</p><h3><strong>The Advantages of Implementing Angular Libraries:</strong></h3><p>By implementing Angular libraries, we can achieve several advantages, including:</p><ul><li>Improved maintainability<br>Because we are no longer duplicating code across multiple projects, it is easier to maintain and update our code over time. We can make changes to a component or service in a single library and have those changes automatically propagate to all of the projects that used that library.</li><li>Faster development<br>By reusing common code and functionality across multiple projects, we are able to develop new applications faster and with fewer errors. We can focus on building the application’s features, rather than spending time duplicating code and functionality.</li><li>Consistency<br>By using the same set of libraries across multiple projects, we are able to ensure that our applications are consistent in terms of functionality and declaration. This helps us build a more cohesive set of applications.</li></ul><h3>How can we use library?</h3><p>In this article, we will cover steps to create a library and how to use it in multiple Apps.</p><h3>Creating a Custom Angular Library</h3><ul><li>Create a workspace project that includes configuration files and the necessary node_modules<br> With the workspace set up, we can then generate a new library project using the following command</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*sLYfJrtrNRK30EmWHnGUog.png" /></figure><ul><li>If we want our library components to be distinct then we can use the --prefix flag. If we don’t, Angular CLI will use lib by default</li><li>That will be created a Boilerplate code for library project. And having library module, services, components, etc. you can see below changes made in library project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*3b55rm9vWNo6TMXwtzQ_dA.png" /><figcaption>custom library project</figcaption></figure><ul><li>Angular.json will get updated with projectType = “library”.</li><li>To make library code reusable you must define a public API for it. <strong>public-api.ts</strong> file contains exported files which is public and ready to reuse in different Angular Apps.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*qQUIIL30mGZVMqh-9mCWTA.png" /><figcaption>public-api.ts</figcaption></figure><ul><li>Then make a functionality into your library. Your library is ready to use. Build your library with ng-build command</li></ul><h3>Rebuilding our library</h3><p>After making the changes, we need to rebuild our library with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*3P60yOuENBqKP250B_iH5Q.png" /></figure><p>This creates an <strong>my-lib directory</strong> in our workspace’s <strong>dist</strong> directory.</p><h3>Publishing your library:</h3><p>Based on the <a href="https://angular.io/guide/creating-libraries#publishing-libraries">Angular documentation</a>, there are 2 types of distribution formats in publishing a library, Partial-Ivy and Full-Ivy. Partial-Ivy is the recommended format because it will be supported by different Angular versions across projects which use Ivy, while Full-Ivy will require the same Angular version between the library and the project that consumes it.</p><p>Initially, Angular CLI will use Partial-Ivy. We can see the configuration in tsconfig.lib.prod.json, the “compilationMode” value is “partial”. If we want to use Full-Ivy, we can change it to “compilationMode”: “full”.</p><p>We publish the library to make the library available on npm. For publishing the library, all we need to do is create a production build, and then run npm publish command from the library project’s dist directory.<br>The Syntax is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*MFB5X2CNfkh23mERbEDWrg.png" /></figure><p>If you have not published anything before, you will need to create an npm account first and log in into your <a href="https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry">npm accoun</a>t and then publish your library.</p><h3>Conclusion:</h3><p>Implementing Angular libraries can offer numerous benefits for developers and organizations alike. By reusing code across multiple projects, we can reduce duplication and ensure consistency while also saving time and effort.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4a4a1a1f76e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>