Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelbela committed Dec 4, 2022
0 parents commit 51c0ceb
Show file tree
Hide file tree
Showing 11 changed files with 4,013 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# My Awesome normalizr
8 changes: 8 additions & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}

3,239 changes: 3,239 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "nomalize-tool",
"version": "1.0.1",
"description": "my normalizr tool",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"test": "jest --config jestconfig.json",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "tslint -p tsconfig.json",
"prepare": "npm run build",
"prepublishOnly": "npm run test && npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "https://git.garena.com/yuqing.yang/my-awesome-normalizr.git"
},
"keywords": [
"normalize"
],
"author": "yuqing.yang",
"license": "ISC",
"devDependencies": {
"@types/jest": "^27.0.2",
"jest": "^27.2.4",
"prettier": "^2.4.1",
"ts-jest": "^27.0.5",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.4.3"
},
"files": [
"lib/**/*"
]
}
163 changes: 163 additions & 0 deletions src/__tests__/__snapshots__/schema.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`denormalize denormalizes entities 1`] = `
Array [
Object {
"id": 1,
"type": "foo",
},
Object {
"id": 2,
"type": "bar",
},
]
`;

exports[`denormalize denormalizes nested entities 1`] = `
Object {
"author": Object {
"id": "8472",
"name": "Paul",
},
"body": "This article is great.",
"comments": Array [
Object {
"comment": "I like it!",
"id": "comment-123-4738",
"user": Object {
"id": "10293",
"name": "Jane",
},
},
],
"id": "123",
"title": "A Great Article",
}
`;

exports[`denormalize set to undefined if schema key is not in entities 1`] = `
Object {
"author": undefined,
"comments": Array [
Object {
"user": undefined,
},
],
"id": "123",
}
`;

exports[`normalize ignores null values 1`] = `
Object {
"entities": Object {},
"result": Array [
null,
],
}
`;

exports[`normalize ignores null values 2`] = `
Object {
"entities": Object {},
"result": Array [
undefined,
],
}
`;

exports[`normalize ignores null values 3`] = `
Object {
"entities": Object {},
"result": Array [
false,
],
}
`;

exports[`normalize normalizes entities 1`] = `
Object {
"entities": Object {
"tacos": Object {
"1": Object {
"id": 1,
"type": "foo",
},
"2": Object {
"id": 2,
"type": "bar",
},
},
},
"result": Array [
1,
2,
],
}
`;

exports[`normalize normalizes entities with circular references 1`] = `
Object {
"entities": Object {
"users": Object {
"123": Object {
"friends": Array [
123,
],
"id": 123,
},
},
},
"result": 123,
}
`;

exports[`normalize normalizes nested entities 1`] = `
Object {
"entities": Object {
"articles": Object {
"123": Object {
"author": "8472",
"body": "This article is great.",
"comments": Array [
"comment-123-4738",
],
"id": "123",
"title": "A Great Article",
},
},
"comments": Object {
"comment-123-4738": Object {
"comment": "I like it!",
"id": "comment-123-4738",
"user": "10293",
},
},
"users": Object {
"10293": Object {
"id": "10293",
"name": "Jane",
},
"8472": Object {
"id": "8472",
"name": "Paul",
},
},
},
"result": "123",
}
`;

exports[`normalize passes over pre-normalized values 1`] = `
Object {
"entities": Object {
"articles": Object {
"123": Object {
"author": 1,
"id": "123",
"title": "normalizr is great!",
},
},
},
"result": "123",
}
`;
Loading

0 comments on commit 51c0ceb

Please sign in to comment.