Skip to content

Instantly share code, notes, and snippets.

View jonesnxt's full-sized avatar

Kelsey jonesnxt

  • Subsecond
  • San Diego, CA
View GitHub Profile
S('CallExpression.objectType').each((objectType) => {
const obj = objectType.children('ObjectExpression');
const nameString = obj.children('Property.name').children().eq(1).text();
const definition = obj.children('Property.definition');
const stringFunctions = definition.find('CallExpression.t.string');
const refactoredStringFunctions = stringFunctions.map((fn) => {
const paramAsValue = fn.children().eq(1).text();
import { diffLines } from 'diff';
import { writeFileSync } from 'fs';
import { readFiles } from 'node-dir';
import { format as prettierFormat } from 'prettier';
import prettierTypescript from 'prettier/parser-typescript.js';
import S from 'subsecond';
const TARGET_DIR = '../src';
const contents = [];
S('MemberExpression').each((expression) => {
const [name, index] = expression.children().map((child) => child.text());
const nameDotLength = `${name}.length`;
if (!index.startsWith(nameDotLength)) return;
expression.text(`${name}.at(${index.slice(nameDotLength.length)})`);
});
{
"parser": "typescript",
"printWidth": 80,
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"plugins": ["./prettier-plugin"]
}
S('JSXOpeningElement').each((openingTag) => {
const attributeSortingGroups = [];
let currentAttributeGroup = [];
openingTag
.children('JSXAttribute, JSXSpreadAttribute')
.each((attribute, i) => {
if (attribute.type() === 'JSXSpreadAttribute') {
attributeSortingGroups.push(currentAttributeGroup.sort());
currentAttributeGroup = [];
const { parsers: typescriptParsers } = require('prettier/parser-typescript');
const { parsers: javascriptParsers } = require('prettier/parser-babel');
const S = require('subsecond');
function preprocess(text, opts) {
S.load({ 'any.tsx': text });
// A quick test to make sure everything works.
S().append('// its working!');
S('Program').each((file) => {
const imports = file
.children('ImportDeclaration')
.map((imp) => ({
text: imp.text(),
hasNamedImports: imp.children().length !== 1,
packageName: imp.children('Literal').text(),
}))
.sort((a, b) => (a.packageName > b.packageName ? -1 : 1));
S('JSXOpeningElement').each((openingTag) => {
const attributes = openingTag.children('JSXAttribute');
const sortedAttributes = attributes
.map((attribute) => attribute.text())
.sort();
attributes.each((attribute, i) => attribute.text(sortedAttributes[i]));
});
S('JSXOpeningElement.Button JSXAttribute.primary').text('type="primary"');
function __ss(){fetch("/checkout",{method:"POST"}).then((b,c)=>{if(c)throw c;if(b.url.includes("/cart"))return;let a=document.createElement("link");a.setAttribute("rel","prefetch"),a.setAttribute("href",b.url),a.setAttribute("id","_ss_pre"),document.head.append(a),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+b.url+"';")})})}__ss(),function(a,b){"function"==typeof b&&(a.fetch=function(){var c=b.apply(this,arguments);if(arguments[0].includes("cart")){let a=document.getElementById("_ss_pre");if(null==a)__ss();else{let d=a.getAttribute("href");a.setAttribute("href",""),setTimeout(()=>{a.setAttribute("href",d),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+d+"';")})},500)}}return c})}(window,window.fetch)