This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe, expect, it } from 'vitest'; | |
import jscodeshift from 'jscodeshift'; | |
import migrateDefaultExportsToNamedImports from './migrate-default-exports-to-named-exports'; | |
const testData = { | |
fileWithDefaultExport: { | |
before: ` | |
const SomeOtherVar = 'should be unchanged'; | |
const MyExport = 'this should change'; | |
function MyFunctionExport() { return 'this should change' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This codemod migrates usage of default exports to named exports instead | |
See migrate-default-exports-to-named-exports.test.js for before/after examples. | |
*/ | |
export const parser = 'tsx'; | |
const generateNamedExportDeclaration = (jscodeshift, inlineDefaultExport, filePath) => { | |
const declarationType = inlineDefaultExport.node.declaration.type; | |
if (declarationType === 'FunctionDeclaration' || declarationType === 'ClassDeclaration') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this logic is based on the "using out-of-phase sine waves to make rainbows" section described | |
# here https://krazydad.com/tutorials/makecolors.php, implemented in bash. | |
# Uses the more modern rgb escape code sequence (ESC[38;2;{red};{green};{blue}m), so will only work on newer terminals | |
# It's uh, very slow | |
function print_rainbow { | |
local text_to_print=$1 | |
local result="" | |
local frequency | |
frequency=$(echo "3.14159 * 1.8 / ${#text_to_print}" | bc -l) | |
for (( i=0; i<${#text_to_print}; i++ )); do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Terminal text formatting functions, using ANSI escape sequences with specific formatting codes. | |
# Most terminals recognize these as special character sequences that say basically | |
# "anything after this sequence should be bold" (code 1) or "blue" (94) or "italic" (3), etc. | |
# | |
# The main `text_formatting_escape_sequence` function here just wraps any given args in the sequence | |
# for the given formatting code, closing it with the "reset all styles" code (0). | |
# | |
# Further reading: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 | |
function text_formatting_escape_sequence { echo -e "\033[${1}m${*:2}\033[0m"; } | |
function bold { text_formatting_escape_sequence 1 "$@"; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert normalize_date("Jan. 21, 1991") == "1991-01-21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def split_extents(extent_text): | |
# splits by " and ", " in ", and each of the following characters: ,([ | |
regex_to_split_by = r"\,|\[|\(| and | in " | |
extent_list = filter(None, re.split(regex_to_split_by, extent_text)) | |
# the re.split() function removes the characters it splits by, so if we want to | |
# preserve the opening parentheses and brackets, we need to add those back | |
extent_list = ["(" + extent if extent.endswith(")") else extent for extent in extent_list] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from extent_splitter import split_extents | |
class TestExtentSplitter(unittest.TestCase): | |
def setUp(self): | |
self.extent_1_raw_text = "4 linear feet and 1 oversize volume" | |
self.extent_1_target_output = ["4 linear feet", "1 oversize volume"] | |
self.extent_2_raw_text = "1 oversize volume and 5 motion picture reels" | |
self.extent_2_target_output = ["1 oversize volume", "5 motion picture reels"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestExtentSplitter(unittest.TestCase): | |
def setUp(self): | |
(...) | |
def test_split_first_two_element_extent_string(self): | |
split_extent = split_extents(self.extent_1_raw_text) | |
self.assertEqual(split_extent, self.extent_1_target_output) | |
# def (remaining completed tests...), etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_extents(extent_text): | |
extents = extent_text.split(",") | |
extents = filter(None, [item for extent in extents for item in extent.split(" and ")]) | |
extents = [extent.strip(" ") for extent in extents] | |
return extents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_extents(extent_text): | |
text_split = extent_text.split(" and ") | |
extent_list = [] | |
# now that the sentence is split by "and", let's split each of | |
# the two resulting items by commas, appending the result to | |
# a new list | |
for extent in text_split: | |
extent_list.append(extent.split(",")) |
NewerOlder