Skip to content

Commit

Permalink
Merge 61ac076 into c4b98f9
Browse files Browse the repository at this point in the history
  • Loading branch information
heyjul3s committed Feb 8, 2021
2 parents c4b98f9 + 61ac076 commit 01372ac
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/hextorgb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "dist/hextorgb.cjs.js",
"module": "dist/hextorgb.esm.js",
"src": "src/index.ts",
"types": "dist/src/index.d.ts",
"directories": {
"lib": "src",
"test": "__tests__"
Expand All @@ -30,5 +31,8 @@
"bugs": {
"url": "https://github.com/heyjul3s/artifak/issues"
},
"homepage": "https://github.com/heyjul3s/artifak#readme"
"homepage": "https://github.com/heyjul3s/artifak#readme",
"devDependencies": {
"@artifak/bundler": "^1.1.3"
}
}
4 changes: 2 additions & 2 deletions packages/hextorgb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist",
"rootDir": "."
},
"exclude": ["dist", "node_modules"],
"references": [],
"include": ["src"]
}
9 changes: 9 additions & 0 deletions packages/media/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "."
},
"references": [],
"include": ["src"]
}
11 changes: 11 additions & 0 deletions packages/pxtoem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `@artifak/pxtoem`

> TODO: description
## Usage

```
const pxtoem = require('@artifak/pxtoem');
// TODO: DEMONSTRATE API
```
54 changes: 54 additions & 0 deletions packages/pxtoem/__tests__/pxtoem.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
pxToEm,
getPxNumericValue,
extractPxNumericValue
} from '../src/pxtoem';

describe('@artifak/pxtoem', () => {
it('returns value of "0em" when provided with false-like args', () => {
expect(pxToEm(void 0 as any)).toEqual('0em');
expect(pxToEm(null as any)).toEqual('0em');
expect(pxToEm(false as any)).toEqual('0em');
expect(pxToEm(NaN as any)).toEqual('0em');
});

it('returns a string EM value of 3 when provided a numeric value of "48"', () => {
expect(pxToEm(48)).toEqual('3em');
});

it('returns a string EM value of 3 when provided with a string value of "48PX"', () => {
expect(pxToEm('48px')).toEqual('3em');
});
});

describe('getPxNumericValue', () => {
it('should return only the numeric type value when given a "PX" numeric value', () => {
expect(getPxNumericValue('1px')).toEqual(1);
});

it('should return only the numeric type value when given a "EM" numeric value', () => {
expect(getPxNumericValue('2em')).toEqual(2);
});

it('should return only the numeric type value when given a "REM" numeric value', () => {
expect(getPxNumericValue('3rem')).toEqual(3);
});

it('should return only the numeric type value when given a "DPI" numeric value', () => {
expect(getPxNumericValue('4dpi')).toEqual(4);
});

it('should return only the numeric type value when given a "PT" numeric value', () => {
expect(getPxNumericValue('5pt')).toEqual(5);
});
});

describe('extractPxNumericValue', () => {
it('should return only the numeric type value when given a float string value', () => {
expect(extractPxNumericValue('0.123px')).toEqual(0.123);
});

it('should return only the numeric type value when given an integer string value', () => {
expect(extractPxNumericValue('1px')).toEqual(1);
});
});
38 changes: 38 additions & 0 deletions packages/pxtoem/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@artifak/pxtoem",
"version": "1.0.0",
"description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
"keywords": [],
"author": "heyjul3s <julian.cy.low@gmail.com>",
"license": "ISC",
"sideEffects": false,
"module": "dist/pxtoem.esm.js",
"main": "dist/pxtoem.cjs.js",
"src": "src/index.ts",
"types": "dist/src/index.d.ts",
"directories": {
"src": "src",
"test": "__tests__"
},
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/heyjul3s/artifak.git"
},
"scripts": {
"build": "rimraf dist && builder",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/heyjul3s/artifak/issues"
},
"homepage": "https://github.com/heyjul3s/artifak#readme",
"devDependencies": {
"@artifak/bundler": "^1.1.3"
}
}
1 change: 1 addition & 0 deletions packages/pxtoem/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { pxToEm } from '../src/pxtoem';
21 changes: 21 additions & 0 deletions packages/pxtoem/src/pxtoem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function pxToEm(size: number | string, baseSize = 16): string {
const pxValue = getPxNumericValue(size);
return `${pxValue / baseSize}em`;
}

export function getPxNumericValue(size: number | string): number {
if (Object.prototype.toString.call(size) === '[object String]') {
return extractPxNumericValue(size as string);
}

if (!!size) {
return size as number;
}

return 0;
}

export function extractPxNumericValue(size: string): number {
const WORD_REGEX = /(\D*)$/i;
return Number(size.replace(WORD_REGEX, ''));
}
9 changes: 9 additions & 0 deletions packages/pxtoem/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "."
},
"references": [],
"include": ["src"]
}

0 comments on commit 01372ac

Please sign in to comment.