投稿時間:2023-03-04 23:10:39 RSSフィード2023-03-04 23:00 分まとめ(11件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… 楽天ブックス、Google製品が最大50%オフになるセールなど多数のセールを開催中 https://taisy0.com/2023/03/04/169248.html pixelwa 2023-03-04 13:00:53
python Pythonタグが付けられた新着投稿 - Qiita PCAによる特徴量自動生成 https://qiita.com/mkdirman/items/f05f5e5031b4795b02a6 専門用語 2023-03-04 22:31:17
Ruby Rubyタグが付けられた新着投稿 - Qiita Rails いいね機能の非同期通信化(Ajax)について! https://qiita.com/momozo_trademen/items/cffc9ece7530db6d07bf rails 2023-03-04 22:13:06
Ruby Railsタグが付けられた新着投稿 - Qiita Rails いいね機能の非同期通信化(Ajax)について! https://qiita.com/momozo_trademen/items/cffc9ece7530db6d07bf rails 2023-03-04 22:13:06
海外TECH MakeUseOf Why TikTok's Bold Glamour Filter Is So Controversial https://www.makeuseof.com/why-tiktoks-bold-glamour-filter-controversial/ tiktok 2023-03-04 13:03:30
海外TECH DEV Community 10 Helpful JavaScript Utility Functions https://dev.to/dostonnabotov/10-helpful-javascript-utility-functions-35oc Helpful JavaScript Utility FunctionsHey there Today we ll cover custom utility functions in JavaScript that can come in handy in most of your projects Table of Contents console log querySelector addEventListener random times slugify validateEmail capitalize sanitizeHTML localStorage ResourcesConclusion console log Yes the tool we all love and use for printing debugging etc So why not shorten it to reduce typing and save some time const log console log Hello world Expected output Hello world SAME AS console log Hello world Expected output Hello world Explanation we use the destructuring assignment to be able to extract the log method from the console querySelector When working with JavaScript you might have heard the term DOM Manipulation and used getElementById querySelector and other methods to access the DOM elements So let s make it easier to work with const select selector scope document gt return scope querySelector selector const title select h const className select class const message select message formElem SAME AS const title document querySelector h const className document querySelector class const message formElem querySelector message Explanation We re passing parameters in the select function st DOM element you want to selectnd Scope from which you access that element default document addEventListener Handling the click mousemove and other events are mostly implemented with the addEventListener method const listen target event callback options gt return target addEventListener event callback options listen buttonElem click gt console log Clicked listen document mouseover gt console log Mouse over listen formElem submit gt console log Form submitted once true Explanation We re passing parameters in the listen function st Element you want to target e g window document or specific DOM element nd Event type e g click submit DOMContentLoaded etc rd Callback functionth Remaining optional options e g capture once etc Also we use the spread syntax to allow for other options if necessary Otherwise it can be omitted just like in the addEventListener method random You might probably be aware of Math random function that generates random numbers from to You might also know about other hacks like Math random which should now generate random numbers from to However the problem is that despite knowing the limit we don t have much control over the minimum value const random min max gt return Math floor Math random max min min random Explanation Here s the better explanation by MDN Docs times Sometimes we often find ourselves in need of running a particular function several times Of course we can use setInterval to run every interval amount of time like this setInterval gt randomFunction runs every secondsThe problem is that we aren t able to specify how many times we want to run it So let s fix it const times func n gt Array from Array n forEach gt func times gt randomFunction runs timesExplanation Array n creates a new array with the length of n Array gt Array from creates a shallow copy from Array n It helps us to make an array to be usable filling it with undefined You can also use the Array prototype fill method to achieve the same result Array from Array gt undefined undefined undefined Note While researching this utility function I realized that some programmers prefer to put the n parameter first and then the function times n func But it looked kinda weird to me so I decided to swap their places thus making the syntax more similar to the setInterval function setInterval func delay times func n Also you call it setTimes instead of times to match with the setInterval and setTimeout methods depending on your preferences slugify Have you ever found yourself in need of turning the title of your blog articles into a URL like format JS Utility Functions gt js utility functionsHere is a little utility function that does so const slugify string separator gt return string toString Cast to string optional toLowerCase Convert the string to lowercase letters trim Remove whitespace from both sides of a string optional replace s g separator Replace spaces with replace w g Remove all non word chars replace g separator Replace with replace g separator Replace multiple with single replace g Remove trailing slugify Hello World Expected output hello world slugify Hello Universe Expected output hello universe Explanation Here is the discussion by the GitHub community validateEmail When working on small projects and trying out email validation for your form you can use this super simple method to achieve your goal Also it can be very handy for small tests const validateEmail email gt const regex S S S return regex test email validateEmail youremail org com truevalidateEmail youremail com falsevalidateEmail youremail org com falseExplanation You can play around with the regex here RegExp test searches if the provided regex expression matches with the stringNote For larger projects I would recommend using libraries like validator js to handle heavy lifting for you capitalize We have built in toUpperCase and toLowerCase methods in JavaScript However we don t have built in support for capitalization So let s build one const capitalize str gt const arr str trim toLowerCase split for let i i lt arr length i arr i arr i charAt toUpperCase arr i slice return arr join capitalize hello world Expected output Hello World Explanation split turns the string into an arrayarr i charAt toUpperCase upper cases the st letter of each wordarr i slice returns the remaining word letters arr join turns the array back into string sanitizeHTML Ever heard of Cross site scripting XSS attacks If not it s a type of attack that occurs on most websites For example when submitting a form an attacker might try to send malicious scripts to break into the system To prevent this from happening on your forms you can use this handy function that will sanitize the script code const sanitizeHTML str gt const div document createElement div div textContent str return div innerHTML sanitizeHTML lt h gt Hello World lt h gt Expected output amp lt h amp gt Hello World amp lt h amp gt Explanation Unlike innerHTML textContent does not parse the string as HTML while innerText only shows human readable elements Moreover using textContent can prevent XSS attacks MDN Docs localStorage You might have used localStorage in your to do list applications or any other projects to save the particular data in the user s computer memory When getting and setting items you have to use JSON parse and stringify methods to achieve the desired result So let s make it easier to work with them const storage get key defaultValue null gt const value localStorage getItem key return value JSON parse value defaultValue set key value gt localStorage setItem key JSON stringify value remove key gt localStorage removeItem key clear gt localStorage clear storage set motto Eat Sleep Code Repeat storage get motto Explanation If you aren t aware of JSON parse and stringify methods check out the MDN Docs for a better explanation Note It was quite tough for me to come up with a good name that would make much more sense than just storage Because at first glance developers might not know whether it s referring to the localStorage or something else However you can name it whatever you want Also if you ve found any good names please do let me know in the comments section ResourcesMDN Docs JavaScript Functions YouTubeJS Utility Functions Web Dev Simplifiedmany more ConclusionIf you ve any questions or suggestions the comment section is all yours We might make part of this article with your suggestions Thanks for reading Back to Top 2023-03-04 13:13:50
Apple AppleInsider - Frontpage News Satechi Pro Hub Slim review: Good port expansion for Mac, on a budget https://appleinsider.com/articles/23/03/04/satechi-pro-hub-slim-review-good-port-expansion-for-mac-on-a-budget?utm_medium=rss Satechi Pro Hub Slim review Good port expansion for Mac on a budgetOne of Satechi s newest docks is the Pro Hub Slim which adds seven additional ports to the latest MacBook Pro and MacBook Air models Pro Hub SlimThe company released it in January and specifically designed it for MacBooks with an M series chip These models have two Thunderbolt ports on the left side and that s how the Pro Slim Hub connects to the machine Read more 2023-03-04 13:47:23
Apple AppleInsider - Frontpage News Daily deals March 4: $400 off M1 Pro 14-inch MacBook Pro, $100 off iPad Air, $50 off Apple Watch Ultra, more https://appleinsider.com/articles/23/03/04/daily-deals-march-4-400-off-m1-pro-14-inch-macbook-pro-100-off-ipad-air-50-off-apple-watch-ultra-more?utm_medium=rss Daily deals March off M Pro inch MacBook Pro off iPad Air off Apple Watch Ultra moreToday s top deals include a MagSafe charger a MagSafe Battery Pack an Gen Apple Pencil and more Apple Watch Ultra and the M Pro inch MacBook Pro feature in Saturday s dealsThe AppleInsider staff explores the internet for deals at online retailers to curate a list of amazing deals on the top tech items including discounts on Apple products TVs accessories and other gadgets We share our top finds in our Daily Deals list to help put get the most bang for your buck Read more 2023-03-04 13:27:40
ニュース BBC News - Home Loud bang prompts calls to Leicestershire Police https://www.bbc.co.uk/news/uk-england-leicestershire-64847214?at_medium=RSS&at_campaign=KARANGA sonic 2023-03-04 13:45:38
ニュース BBC News - Home Sergei Lavrov: Russian foreign minister laughed at for Ukraine war claims https://www.bbc.co.uk/news/world-europe-64848508?at_medium=RSS&at_campaign=KARANGA ukraine 2023-03-04 13:29:54
ニュース BBC News - Home Channel ferry blaze: Isle of Innisfree towed to Calais https://www.bbc.co.uk/news/uk-england-kent-64847029?at_medium=RSS&at_campaign=KARANGA engine 2023-03-04 13:45:49

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)