generated from qq15725/starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
384 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
export function getNestedValue(obj: any, path: (string | number)[], fallback?: any): any { | ||
const last = path.length - 1 | ||
if (last < 0) | ||
return obj === undefined ? fallback : obj | ||
for (let i = 0; i < last; i++) { | ||
if (obj == null) { | ||
return fallback | ||
} | ||
obj = obj[path[i]] | ||
} | ||
if (obj == null) | ||
return fallback | ||
return obj[path[last]] === undefined ? fallback : obj[path[last]] | ||
} | ||
|
||
export function getObjectValueByPath(obj: any, path: string, fallback?: any): any { | ||
// credit: http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key#comment55278413_6491621 | ||
if (obj == null || !path || typeof path !== 'string') | ||
return fallback | ||
if (obj[path] !== undefined) | ||
return obj[path] | ||
path = path.replace(/\[(\w+)\]/g, '.$1') // convert indexes to properties | ||
path = path.replace(/^\./, '') // strip a leading dot | ||
return getNestedValue(obj, path.split('.'), fallback) | ||
} | ||
|
||
export function setNestedValue(obj: any, path: (string | number)[], value: any): void { | ||
const last = path.length - 1 | ||
for (let i = 0; i < last; i++) { | ||
if (typeof obj[path[i]] !== 'object') | ||
obj[path[i]] = {} | ||
obj = obj[path[i]] | ||
} | ||
obj[path[last]] = value | ||
} | ||
|
||
export function setObjectValueByPath(obj: any, path: string, value: any): void { | ||
if (typeof obj !== 'object' || !path) | ||
return | ||
path = path.replace(/\[(\w+)\]/g, '.$1') | ||
path = path.replace(/^\./, '') | ||
return setNestedValue(obj, path.split('.'), value) | ||
} | ||
|
||
export function isObject(objectable: any): objectable is object { | ||
return objectable !== null && typeof objectable === 'object' && !Array.isArray(objectable) | ||
} | ||
|
||
export function deepMerge( | ||
source: Record<string, any> = {}, | ||
target: Record<string, any> = {}, | ||
out: Record<string, any> = {}, | ||
): Record<string, any> { | ||
for (const key in source) { | ||
out[key] = source[key] | ||
} | ||
for (const key in target) { | ||
const sourceProperty = source[key] | ||
const targetProperty = target[key] | ||
if ( | ||
isObject(sourceProperty) | ||
&& isObject(targetProperty) | ||
) { | ||
out[key] = deepMerge(sourceProperty, targetProperty) | ||
continue | ||
} | ||
out[key] = targetProperty | ||
} | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import { defineElement, OXML } from '../../core' | ||
import { defineChild, defineElement, OXML } from '../../core' | ||
|
||
/** | ||
* https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.outline | ||
*/ | ||
@defineElement('a:ln') | ||
export class Outline extends OXML { | ||
@defineChild('a:bevel') declare bevel: OXML | ||
@defineChild('a:custDash') declare custDash: OXML | ||
@defineChild('a:extLst') declare extLst: OXML | ||
@defineChild('a:gradFill') declare gradFill: OXML | ||
@defineChild('a:headEnd') declare headEnd: OXML | ||
@defineChild('a:miter') declare miter: OXML | ||
@defineChild('a:noFill') declare noFill: OXML | ||
@defineChild('a:pattFill') declare pattFill: OXML | ||
@defineChild('a:prstDash') declare prstDash: OXML | ||
@defineChild('a:round') declare round: OXML | ||
@defineChild('a:solidFill') declare solidFill: OXML | ||
@defineChild('a:tailEnd') declare tailEnd: OXML | ||
|
||
// <a:solidFill> | ||
// <a:srgbClr val="transparent"> | ||
// <a:alpha val="100000"/> | ||
// </a:srgbClr> | ||
// </a:solidFill> | ||
// <a:prstDash val="solid" /> | ||
// <a:headEnd type="none" /> | ||
// <a:tailEnd type="none" /> | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.