Skip to content

Instantly share code, notes, and snippets.

View PeterKow's full-sized avatar
πŸ‘¨β€πŸ’»

Peter Kowalczyk PeterKow

πŸ‘¨β€πŸ’»
View GitHub Profile
@PeterKow
PeterKow / UK-number-validation.js
Created April 23, 2019 10:12
Validate UK number
export function isValidUKPhone(phone: string) {
const re = /^(\+44\d{10}\b)/;
return re.test(phone);
}
describe('isValidUKPhone', () => {
it('should return true as valid number', () => {
const phone = '+447473222885';
expect(isValidUKPhone(phone)).toBeTruthy();
});
@PeterKow
PeterKow / cross-platform.structure.js
Last active August 13, 2018 20:38
Example for cross platform repo structure
β”œβ”€β”€ pages (SEO and Web related configuration)
β”œβ”€β”€ server (node relates stuff. eg. Next.js)
β”œβ”€β”€ static
β”œβ”€β”€ src
| β”œβ”€β”€ native (abstraction for cross-platform components)
| β”œβ”€β”€ routing (abstraction for routing with routes)
| β”œβ”€β”€ constcans (const variables)
| β”œβ”€β”€ config (shared project configuration, env variables)
| β”œβ”€β”€ constans ()
| β”œβ”€β”€ helpers (simple helpers)
@PeterKow
PeterKow / Feature-Type-grouping.js
Created August 13, 2018 13:49
Example for feature type grouping
β”œβ”€β”€ src
| β”œβ”€β”€ orders (feature)
| β”œβ”€β”€ asstes (type)
| β”œβ”€β”€ orders.png
| β”œβ”€β”€ components (type)
| β”œβ”€β”€ order.jsx
| β”œβ”€β”€ order-list.jsx
| β”œβ”€β”€ order.styles.js/css
| β”œβ”€β”€ logic (type)
| β”œβ”€β”€ order.api.js
@PeterKow
PeterKow / types-grouping.js
Last active August 13, 2018 13:44
Example for type grouping
β”œβ”€β”€ src
| β”œβ”€β”€ asstets (type)
| β”œβ”€β”€ order.png
| β”œβ”€β”€ components (type)
| β”œβ”€β”€ common
| β”œβ”€β”€ button.jsx
| β”œβ”€β”€ avatar.jsx
| β”œβ”€β”€ order.jsx
| β”œβ”€β”€ order-list.jsx
| β”œβ”€β”€ payment.jsx
@PeterKow
PeterKow / Feature-grouping.js
Last active August 13, 2018 13:44
Example of Feature grouping
β”œβ”€β”€ src
| β”œβ”€β”€ orders (feature - all things related to Orders should be in this folder )
| β”œβ”€β”€ order.styles.js/css
| β”œβ”€β”€ order.api.js
| β”œβ”€β”€ order.redux.js
| β”œβ”€β”€ order.jsx
| β”œβ”€β”€ order-list.jsx
| β”œβ”€β”€ payments (feature - all things related to Payments should be in this folder )
| β”œβ”€β”€ payment.api.js
| β”œβ”€β”€ payment.redux.js
var obj = Immutable.fromJS({ data: 'Some data' })
obj.get('data') //Some data
obj.data //undefined
var obj = Immutable.fromJS({ data: 'No data' })
var newObj = newObj.set('data', 'Mutated successfully')
var obj = Immutable({ data: 'No data' })
obj.data //No data
// Note: There is getIn for nested objects
@PeterKow
PeterKow / Seamless-immutable-set.js
Created August 7, 2018 15:45
Seamless-immutable-set
var obj = Immutable({ data: 'No data' })
var newObj = Immutable.set(obj, 'data', 'Mutated successfully')
//Alternative
var newObj = obj.set('data', 'Mutated successfully')
@PeterKow
PeterKow / Immutablejs.js
Created August 7, 2018 15:35
Immutablejs example
var array = Immutable.List([])
array[1] = "I'm going to mutate you!"
array[1] // "I'm going to mutate you!" - while immutablejs has it's internal strucure
// To update
var newArray = array.push("I'm going to mutate you!")
newArray.get(0) // "I'm going to mutate you!"
newArray[0] // undefined