Here you can find my private notes about programming that I wanted to share with you. Feel free to filter based on the topic you want or search for something specific.
Create a breadcrumb list of links with JavaScript and use it inside your React applications!
The advantages of using breadcrumbs in your web applications are widely known.
The users get a chain of links that helps them understand where they are in your website and how they came to this page, and how provides them an easy when to navigate back in the hierarchy of links.
Breadcrumbs are considered to be a best practice for the SEO of your application.
Suppose we have the following example of chained links in a breadcrumb:
Main page > Main category 1 > Sub category 1 > Product 1
How to check if a string in JavaScript contains only numbers
There is often the case that you want to check if a string in JavaScript contains only numbers or you might just want to extract the numbers from a string, but you want to do this extraction only when the string only contains numbers. The most common case for such check is when you want to read a value (returned as string from JavaScript) from an input field of a form and evaluate if this value is a number or not.
How to convert a number in Less code into a valid CSS measuring unit
When working with less you most probably have to do some calculations and assign their result in a CSS property, for example into a width of a CSS class or a margin of an CSS id.
Apart from the calculated number you want to generate valid CSS code, so you also have to apply a measuring unit to this number, for example pixels or ems or percentages.
Is there a naming convention for TypeScript interfaces?
The TypeScript language was created from Microsoft as a super-set of typed-rules for JavaScript. The language contains features that one finds in C#, something that is completely understandable since the inventor of TypeScript also invented C#.
TypeScript provides interfaces that are used for two main reasons:
Standardize/ Giving a type to an object, by defining the properties that an object contains.
Define a structure of properties and/ or functions that a class has to implement. Doing this way you can define multiple implementations that implement the interface. In this case, the interface works as a contract (known best practice term from C#) that the classes have to respect.