Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=function&page=663&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 7825 results for "function"(438ms)

vanillawebprojects-1741724733419script.js9 matches

@shouser•Updated 1 month ago
6
7// Show input error message
8function showError(input, message) {
9 const formControl = input.parentElement;
10 formControl.className = 'form-control error';
14
15// Show success outline
16function showSuccess(input) {
17 const formControl = input.parentElement;
18 formControl.className = 'form-control success';
20
21// Check email is valid
22function checkEmail(input) {
23 const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
24 if (re.test(input.value.trim())) {
30
31// Check required fields
32function checkRequired(inputArr) {
33 let isRequired = false;
34 inputArr.forEach(function(input) {
35 if (input.value.trim() === '') {
36 showError(input, `${getFieldName(input)} is required`);
45
46// Check input length
47function checkLength(input, min, max) {
48 if (input.value.length < min) {
49 showError(
62
63// Check passwords match
64function checkPasswordsMatch(input1, input2) {
65 if (input1.value !== input2.value) {
66 showError(input2, 'Passwords do not match');
69
70// Get fieldname
71function getFieldName(input) {
72 return input.id.charAt(0).toUpperCase() + input.id.slice(1);
73}
74
75// Event listeners
76form.addEventListener('submit', function(e) {
77 e.preventDefault();
78
1export default function server(request: Request): Response {
2 return new Response(
3 `<!DOCTYPE html>

vanillawebprojects-1741724733419script.js7 matches

@shouser•Updated 1 month ago
22
23// Add transaction
24function addTransaction(e) {
25 e.preventDefault();
26
48
49// Generate random ID
50function generateID() {
51 return Math.floor(Math.random() * 100000000);
52}
53
54// Add transactions to DOM list
55function addTransactionDOM(transaction) {
56 // Get sign
57 const sign = transaction.amount < 0 ? '-' : '+';
74
75// Update the balance, income and expense
76function updateValues() {
77 const amounts = transactions.map(transaction => transaction.amount);
78
95
96// Remove transaction by ID
97function removeTransaction(id) {
98 transactions = transactions.filter(transaction => transaction.id !== id);
99
104
105// Update local storage transactions
106function updateLocalStorage() {
107 localStorage.setItem('transactions', JSON.stringify(transactions));
108}
109
110// Init app
111function init() {
112 list.innerHTML = '';
113
1export default function server(request: Request): Response {
2 return new Response(
3 `<!DOCTYPE html>

vanillawebprojects-1741724733419script.js1 match

@shouser•Updated 1 month ago
6const swap = document.getElementById('swap');
7
8function calculate() {
9 const currency_one = currencyEl_one.value;
10 const currency_two = currencyEl_two.value;
1export default function server(request: Request): Response {
2 return new Response(
3 `<!DOCTYPE html>

vanillawebprojects-1741724733419script.js8 matches

@shouser•Updated 1 month ago
13
14// Fetch random user and add money
15async function getRandomUser() {
16 const res = await fetch('https://randomuser.me/api');
17 const data = await res.json();
28
29// Double eveyones money
30function doubleMoney() {
31 data = data.map(user => {
32 return { ...user, money: user.money * 2 };
37
38// Sort users by richest
39function sortByRichest() {
40 console.log(123);
41 data.sort((a, b) => b.money - a.money);
45
46// Filter only millionaires
47function showMillionaires() {
48 data = data.filter(user => user.money > 1000000);
49
52
53// Calculate the total wealth
54function calculateWealth() {
55 const wealth = data.reduce((acc, user) => (acc += user.money), 0);
56
63
64// Add new obj to data arr
65function addData(obj) {
66 data.push(obj);
67
70
71// Update DOM
72function updateDOM(providedData = data) {
73 // Clear main div
74 main.innerHTML = '<h2><strong>Person</strong> Wealth</h2>';
85
86// Format number as money - https://stackoverflow.com/questions/149055/how-to-format-numbers-as-currency-string
87function formatMoney(number) {
88 return '$' + number.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
89}
1export default function server(request: Request): Response {
2 return new Response(
3 `<!DOCTYPE html>

vanillawebprojects-1741724733419script.js5 matches

@shouser•Updated 1 month ago
6
7// Play & pause video
8function toggleVideoStatus() {
9 if (video.paused) {
10 video.play();
15
16// update play/pause icon
17function updatePlayIcon() {
18 if (video.paused) {
19 play.innerHTML = '<i class="fa fa-play fa-2x"></i>';
24
25// Update progress & timestamp
26function updateProgress() {
27 progress.value = (video.currentTime / video.duration) * 100;
28
43
44// Set video time to progress
45function setVideoProgress() {
46 video.currentTime = (+progress.value * video.duration) / 100;
47}
48
49// Stop video
50function stopVideo() {
51 video.currentTime = 0;
52 video.pause();
1export default function server(request: Request): Response {
2 return new Response(
3 `<!DOCTYPE html>

getFileEmail4 file matches

@shouser•Updated 6 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago