Skip to content

Instantly share code, notes, and snippets.

View shinokada's full-sized avatar

Shinichi Okada shinokada

View GitHub Profile
/*
This script reads the files in the dist directory and creates a new exports object in the package.json file
with the appropriate svelte and types paths for each Svelte component file found in the dist directory,
except for index.js and index.d.ts.
The resulting exports object is structured as follows:
"exports": {
".": {
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js"
},
// Use this script where you have sub-directories
// This script reads the files in the dist directory and creates a new exports object in the package.json file
import fs from 'fs';
import path from 'path';
const distDir = './dist';
const packageJsonPath = './package.json';
const componentNames = fs.readdirSync(distDir);
const componentExports = {};
<script>
import { Heading, Button, Modal, ImagePlaceholder, TextPlaceholder } from 'flowbite-svelte'
let defaultModal = false;
</script>
<Heading tag="h1" customSize="text-5xl">My website</Heading>
<ImagePlaceholder class='my-4'/>
<Button on:click={() => defaultModal = true} class='mb-4'>Default modal</Button>
<TextPlaceholder class='pb-8' size='xxl'/>
<TextPlaceholder class='pb-8' size='xxl'/>
<script lang='ts'>
import "../app.postcss"
import { Navbar, NavBrand, NavLi, NavUl, NavHamburger, Footer, FooterBrand, FooterCopyright, FooterLinkGroup, FooterLink, Hr } from 'flowbite-svelte'
</script>
<Navbar let:hidden let:toggle>
<NavBrand href="/">
<img
src="https://flowbite-svelte.com/images/flowbite-svelte-icon-logo.svg"
class="mr-3 h-6 sm:h-9"
<script lang='ts'>
import "../app.postcss"
import { Navbar, NavBrand, NavLi, NavUl, NavHamburger } from 'flowbite-svelte'
</script>
<Navbar let:hidden let:toggle>
<NavBrand href="/">
<img
src="https://flowbite-svelte.com/images/flowbite-svelte-icon-logo.svg"
class="mr-3 h-6 sm:h-9"
/*
Use this with the following script
```
"write-package-json": "node ./scripts/package-json-writer.js",
"add-exports": "node ./scripts/add-exports-to-package-json.js",
"package:publish": "standard-version && git push --follow-tags origin main && npm run package &&
npm run add-exports && npm run write-package-json && npm publish",
```
This script reads the content of a folder named 'dist' and generates an exports object to be included in the
// reference https://dev.to/builderio/safe-data-fetching-in-modern-javascript-dp4
class ResponseError extends Error {
constructor(message, res) {
super(message)
this.response = res
}
}
export async function myFetch(...options) {
<%- include('partials/header',{title:title}); %>
<h1 class="text-4xl font-bold dark:text-white py-8">
<%= title %>
</h1>
<h2 class="text-3xl dark:text-white py-4">Examples</h2>
<div class="flex flex-wrap justify-between">
<div class="my-4 max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow-md dark:bg-gray-800 dark:border-gray-700">
<a href="/location">
// src/worldcities.js
import { client } from './redis.js';
export const addIntCities = () => {
client.geoadd('cities', 0.0000, 0.0000, "North Pole");
client.geoadd('cities', -0.1278, 51.5074, "London");
client.geoadd('cities', -3.7032, 40.4168, "Madrid");
client.geoadd('cities', -77.0369, 38.9072, "Washington D.C.");
client.geoadd('cities', 139.6917, 35.6895, "Tokyo")
// src/uscities.js
import { client } from './redis.js';
export const addUsCities = () => {
client.geoadd('uscities', -71.0589, 42.3601, "Boston, Massachusetts");
client.geoadd('uscities', -75.1652, 39.9526, "Philadelphia, Pennsylvania");
client.geoadd('uscities', -112.0740, 33.4484, "Phoenix, Arizona");
client.geoadd('uscities', -98.4936, 29.4241, "San Antonio, Texas");
client.geoadd('uscities', -121.8949, 37.3382, "San Jose, California");
client.geoadd('uscities', -97.7431, 30.2672, "Austin, Texas");