Repository: tsivinsky/hi-mom Branch: master Commit: 8d1631d29edb Files: 11 Total size: 9.3 KB Directory structure: gitextract_7ntvilm0/ ├── .babelrc ├── .github/ │ └── workflows/ │ └── test.yml ├── .gitignore ├── .prettierrc ├── README.md ├── index.d.ts ├── index.js ├── index.test.js ├── languages/ │ └── index.js ├── package.json └── rollup.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets": ["@babel/preset-env"] } ================================================ FILE: .github/workflows/test.yml ================================================ name: test on: push: branches: - master pull_request: branches: - master workflow_dispatch: jobs: test: strategy: matrix: os: - ubuntu-latest - macos-latest - windows-latest name: Testing as a good child on ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: 16 - run: npm install --ignore-scripts - run: npm test ================================================ FILE: .gitignore ================================================ /node_modules /lib /coverage .idea/ ================================================ FILE: .prettierrc ================================================ { "tabWidth": 2, "useTabs": false, "semi": true, "singleQuote": false, "endOfLine": "lf", "trailingComma": "es5" } ================================================ FILE: README.md ================================================ # Hi, mom! A blazingly fast JavaScript library to say hi to your mom! ## Install #### yarn ```bash yarn add hi-mom ``` #### npm ```bash npm i hi-mom ``` #### unpkg.com (UMD) ```html ``` ## Usage #### CommonJS ```javascript const { hiMom } = require("hi-mom"); console.log(hiMom()); // Hi, mom! ``` #### ES Modules ```javascript import { hiMom } from "hi-mom"; console.log(hiMom()); // Hi, mom! ``` #### Browser (UMD) ```javascript console.log(hiMom.hiMom()); ``` #### custom mother name ```javascript import { hiMom } from "hi-mom"; console.log(hiMom("Mother")); // Hi, Mother! ``` ## Languages supported - ar - Arabic - ar-IQ - Iraqi Arabic - as - Assamese - az - Azerbaijani - bn - Bengali - bg - Bulgarian - ca - Catalan - cn - Chinese - cs - Czech - da - Danish - de - German - en - English - en-AU - Australian English - en-PT - Pirate Speak - es - Spanish - fa - Persian - fr - French - he - Hebrew - hi - Hindi - hr - Croatian - hu - Hungarian - id - Indonesian - it - Italian - ja - Japanese - ko - Korean - kaa - Karakalpak - lt - Lithuanian - mar - Marathi - ml - Malayalam - ms - Malay - nl-BE - Flemish - nl-NL - Dutch - no - Norwegian - no-NB - Norwegian Bokmål - no-NN - Norwegian Nynorsk - pl - Polish - pt - Portuguese - qt - Crimean - ro - Romanian - ru - Russian - se - Swedish - si - Sinhala - sr - Serbian - ta - Tamil - th - Thai - tl - Filipino - tr - Turkish - tm - Turkmen - ua - Ukrainian - ur - Urdu - vi - Vietnamese - zh - Zhongwen - ug - Uyghur ================================================ FILE: index.d.ts ================================================ import languages from "./languages/index"; /** * Say hi to your mom blazingly fast! * @param name Mother's name * @param language Language of your mother * @example * import { hiMom } from "hi-mom"; * console.log(hiMom()); // Hi, mom! */ export function hiMom( name?: string, language: keyof typeof languages = "en" ): string; /** * Say hi to multiple moms blazingly fast! * @param mothers Your moms * @example * import { hiMoms } from "hi-mom"; * console.log(hiMoms([ * { lang: "en" }, * { lang: "si" }, * ]])); // Hi, mom! ආයුබෝවන්, අම්මේ! */ export function hiMoms( mothers: string | { name?: string; lang?: keyof typeof languages }[] ): string; ================================================ FILE: index.js ================================================ import languages from "./languages/index.js"; /** * A blazingly fast way to say hi to your mom! * @param {string} name - The mom name * @param {string} [language="en"] - The language * @example hiMom() * // "Hi, mom!" * @example hiMom("Kate") * // "Hi, Kate!" * @example hiMom("Maria", "pt") * // "Oi, Maria!" * @returns {string} A greeting to your mom in the informed language */ export function hiMom(name, language = "en") { if (!language || !languages.hasOwnProperty(language)) { throw new Error("Language not yet supported, but hi mom anyway!"); } const regex = /\{{2}([^}]+)\}{2}/; const greeting = languages[language]; const localeName = greeting.split(regex)[1]; return greeting.replace(regex, name || localeName); } export function hiMoms(mothers) { if (typeof mothers == "string") { return hiMom(mothers); } else if (mothers instanceof Array) { return mothers.map((mother) => hiMom(mother?.name, mother?.lang)).join(" "); } throw new Error("Mother type not supported, but hi mom anyway!"); } ================================================ FILE: index.test.js ================================================ import { hiMom } from "./index"; test("should say hi to mom", () => { expect(hiMom()).toBe("Hi, mom!"); }); test("should not say hi to dad", () => { expect(hiMom()).not.toBe("Hi, dad!"); }); test("should say hi to Mother when requested", () => { expect(hiMom("Mother")).toBe("Hi, Mother!"); }); test("should say hi to mom in tamil when requested", () => { expect(hiMom("", "ta")).toContain("வணக்கம் அம்மா"); }); test("should say hi to mom in german when requested", () => { expect(hiMom("", "de")).toContain("Hallo"); }); test("should say hi to mom in danish when requested", () => { expect(hiMom("", "da")).toContain("Hej"); }); test("should say hi to mom in russian when requested", () => { expect(hiMom("", "ru")).toBe("Привет, мама!"); }); test("should say hi to mom in persian when requested", () => { expect(hiMom("", "fa")).toContain("مامان"); }); test("should say hi to Mother in french when requested", () => { expect(hiMom("Mother", "fr")).toContain("Mother"); }); test("should say hi to Mother in arabic when requested", () => { expect(hiMom("", "ar-IQ")).toContain("يمه"); }); test("should say hi to Mother in darija (Moroccan Arabic) when requested", () => { expect(hiMom("", "ar-MA")).toContain("ماما"); }); test("nl-Be should not say the same as nl-NL when requested", () => { expect(hiMom("", "nl-BE")).not.toBe(hiMom("", "nl-NL")); }); test("should say hi to Mother in assamese when requested", () => { expect(hiMom("", "as")).toContain("অ' মা"); }); test("should say hi to mom in pirate speak when requested", () => { expect(hiMom("", "en-PT")).toContain("Ahoy,"); }); test("should say hi to Mother in azerbaijani when requested", () => { expect(hiMom("", "az")).toBe("Salam, ana!"); }); test("should say hi to Mother in Swedish and not Bork Bork!", () => { expect(hiMom("", "se")).toBe("Hej, mamma!"); }); test("should say hi to Mother in Norwegian Bokmål when requested", () => { expect(hiMom("", "no-NB")).toBe("Hei, mamma!"); }); test("should say hi to Mother in Norwegian Nynorsk when requested", () => { expect(hiMom("", "no-NN")).toBe("Hei, mamma!"); }); test("should say hi to Mother in Croatian when requested", () => { expect(hiMom("", "hr")).toBe("Bok, mama!"); }); test("should say hi to Mother in Filipino when requested", () => { expect(hiMom("", "tl")).toBe("Kamusta po, nanay!"); }); test("should say hi to Mother in Crimean when requested", () => { expect(hiMom("", "qt")).toBe("Selâm, anam!"); }); test("should say hi to Mother in Marathi when requested", () => { expect(hiMom("", "mar")).toBe("नमस्कार, आई!"); }); test("should say hi to mom in Bengali when requested", () => { expect(hiMom("", "bn")).toBe("নমস্কার, মা!"); }); test("should throw error when requested", () => { expect(() => hiMom("", "")).toThrowError(/language/i); }); ================================================ FILE: languages/index.js ================================================ export default { ar: "مرحباً, {{امي}}!", "ar-IQ": "هلا, {{يمه}}!", as: "মা, {{অ' মা}}", "ar-MA": "سلام، {{ماما}}", az: "Salam, {{ana}}!", bn: "নমস্কার, {{মা}}!", bg: "Здрасти, {{мамо}}!", ca: "Hola, {{mamà}}!", cn: "你好,{{妈妈}}!", cs: "Ahoj, {{mamá}}!", da: "Hej, {{mor}}!", de: "Hallo, {{Mama}}!", en: "Hi, {{mom}}!", "en-AU": "Hi, {{mum}}!", "en-PT": "Ahoy, {{mom}}!", es: "Hola, {{mamá}}!", fa: "سلام، {{مامان}}!", fr: "Salut, {{maman}}!", he: "שלום, {{מה}}!", hi: "नमस्ते {{मम्मी}}!", hr: "Bok, {{mama}}!", hu: "Szia, {{anya}}!", id: "Hai, {{ibu}}!", it: "Ciao {{mamma}}!", ja: "こんにちは、{{ママ}}!", ko: "안녕, {{엄마}}!", kaa: "Sálem, {{anajan}}!", lt: "Labas, {{mama}}!", mar: "नमस्कार, {{आई}}!", ml: "ഹായ്, {{അമ്മേ}}!", ms: "Hai, {{bapa}}!", "nl-BE": "Hallo, {{moeke}}!", "nl-NL": "Hallo, {{moeder}}!", no: "Hei, {{mamma}}!", "no-NB": "Hei, {{mamma}}!", "no-NN": "Hei, {{mamma}}!", pl: "Cześć, {{matka}}!", pt: "Oi, {{mãe}}!", ro: "Bună, {{mamă}}!", ru: "Привет, {{мама}}!", se: "Hej, {{mamma}}!", si: "ආයුබෝවන්, {{අම්මේ}}!", sr: "Ćao, {{mama}}!", ta: "வணக்கம் {{அம்மா}}", th: "สวัสดีค่ะ, {{มา}}!", tl: "Kamusta po, {{nanay}}!", tr: "Merhaba, {{anne}}!", tm: "Salam, {{eje}}!", ua: "Привіт, {{мама}}!", ur: "سلام، {{امی}}", vi: "Xin chào, {{mẹ}}!", zh: "你好,{{妈妈}}!", ug: "سالام، {{ئاپا}}!", qt: "Selâm, {{anam}}!", }; ================================================ FILE: package.json ================================================ { "name": "hi-mom", "version": "1.2.1", "description": "A blazingly fast JavaScript library to say hi to your mom!", "main": "index.js", "types": "index.d.ts", "keywords": [ "hello-world", "hello", "hi", "mom", "hi-mom" ], "author": "Daniil Tsivinsky", "license": "MIT", "type": "module", "devDependencies": { "@babel/core": "^7.17.8", "@babel/preset-env": "^7.16.11", "jest": "^27.5.1", "rollup": "^2.70.1" }, "scripts": { "prebuild": "npm run test", "build": "rollup -c rollup.config.js", "prepublishOnly": "npm run build", "test": "jest", "coverage": "jest --coverage" }, "exports": { ".": { "require": "./lib/hi-mom.cjs", "import": "./lib/hi-mom.esm.js" } }, "files": [ "lib/", "languages/", "index.d.ts" ] } ================================================ FILE: rollup.config.js ================================================ import { defineConfig } from "rollup"; export default defineConfig({ input: "./index.js", output: [ { file: "./lib/hi-mom.cjs", format: "cjs", exports: "auto", }, { file: "./lib/hi-mom.esm.js", format: "esm", exports: "auto", }, { file: "./lib/hi-mom.umd.js", format: "umd", exports: "auto", name: "hiMom", }, ], });